getProfile() function not following the scale

plugin
macro
imagej
Tags: #<Tag:0x00007fd548d32be0> #<Tag:0x00007fd548d31a10> #<Tag:0x00007fd548d310d8>

#1

Hello,

I noticed that when I use the macro to plot the profile (ie. profile = getProfile();, the x-axis does not follow the scale I set. The plot should look like when I click on Analyze > Plot Profile. Does the function getProfile() only plot using the pixel scale? Is it possible to use that function and make it follow the scale I set? Thanks in advance.

> macro "LineWidth [2]"{
profile =getProfile();   
   Plot.create("Detecting Minima", "X", "Y", profile);
   Plot.show;
minLocs= Array.findMinima(profile, 20);
   Array.sort(minLocs);
   Array.show(minLocs);
   print("\\Clear");
   for (jj= 0; jj < minLocs.length; jj++){
      x= minLocs[jj];
      y = profile[ x ];
      print("x= ", x, " y= ", y);
      toUnscaled(x, y);
      makeOval(x-4,y-4,8,8);
      run("Invert");
      }
run ("Select None");
}

PS. I select a region in the image, then run the macro.

plot using getProfile():
profile1

plot using Analyze > Plot Profile :
profile2


#2

Hey @limellama -

Seems strange. For me I get the same output using your macro versus Analyze > Plot Profile on just a simple square ROI on a built-in sample image (Blobs). Perhaps you can attach your dataset so we can test it out on your same exact image?

What version of ImageJ/Fiji are you running?

eta


#3

Good day!

Here is an adapted version of your macro that works for me:

img = getImageID;
profile = getProfile();
x = Array.getSequence( profile.length );
scaleArray( img, x )
Plot.create( "Detecting Minima", "X", "Y", x, profile );
Plot.show;
minLocs = Array.findMinima( profile, 20 );
Array.sort( minLocs );
minPos = Array.copy( minLocs );
scaleArray( img, minLocs );
Array.show( minLocs );
print( "\\Clear" );
for ( i = 0; i < minLocs.length; i++ ) {
      x = minLocs[i];
      y = profile[ minPos[i] ];
      print( "x= ", x, " y= ", y );
      toUnscaled( x, y );
      makeOval( x-4, y-4, 8, 8 );
      run( "Invert" );
}
run( "Select None" );
exit();
////
function scaleArray( image, array ) {
	front = getImageID;
	selectImage( image );
	for ( i= 0; i < array.length; i++ ) toScaled( array[i] );
	selectImage( front );
}

I must admit it isn’t very elegant …

Regards

Herbie


#4

Hello @etarena,

I am currently using ImageJ 1.51s. Since the desktop I’m using is macOS High Sierra (v. 10.13.3), I had to download ImageJ bundled with Java 1.8.0_101 version. Anyway, below is the image that I am trying to process:


#5

Thank you for your help again, @Herbie! Your script works for now.


#6

In general @limellama … we recommend downloading/using Fiji.

Fiji is Just ImageJ - it is simply a distribution of ImageJ that comes with a bunch of plugins bundled - ready for you to use out-of-the-box. And it’s easily updatable - which is handy as well.

eta :slight_smile: