getSelectionCoordinates doesn't respect scaled x and y values?

I have a macro that flips the Y axis (for purposes of using the coordinates in R) and then saves the x and y coordinates. But before creating a selection I scale the image.

h = getHeight();
name = getTitle();
getSelectionCoordinates(x, y);
tabDelText = “”;
for ( i = 0; i < x.length; i++ ) {
tabDelText += “” + x[i] + “\t” + h - y[i] + “\n”;
}
path = getDirectory( “E:\Mykolas_work_files\GM_Analysis\Splines” )+name;
File.saveString( tabDelText, path + “.txt” );

However, the saved X and Y coordinates are not scaled. I know of the toScaled(x, y) function, though I am not sure if it applies here, and if it does, where should I insert it in the macro.

Thanks,

Antsushi.

Good day Antsushi,

looks like code of mine …

Why don’t you look up the description of “toScaled” here:
https://imagej.nih.gov/ij/developer/macro/functions.html

toScaled(x, y)
Converts unscaled pixel coordinates to scaled coordinates using the properties of the current image or plot. Also accepts arrays.

getSelectionCoordinates( x, y );
toScaled( x, y );

Regards

Herbie

Hi Herbie,

It is your code! And I am grateful to you for it. :slight_smile:

Inserting toScaled (x,y) there saves the X coordinates as scaled but the Y coordinates remain unscaled.

Do you know what might be causing it? Could it be that this code-

tabDelText += “” + x[i] + “\t” + h - y[i] + “\n”;

Where some “tinkering” is made to flip the Y coordinates clashes with or negates the toScaled(x,y) function?

Best,

Antsushi.

Yes, I know it but I think it is really easy to find out:

tabDelText += "" + x[i] + "\t" + y[i] + "\n";

Why does this work?
I know you will not be happy with it, but it should help you to find the answer.

Please try to learn coding ImageJ macros. It is really easy. Start with trying to understand given code examples.

Regards

Herbie

I think the issue with my current macro is that getHeight() doesn’t give me the scaled height. I can view the scaled height via Image -> Show info…, where the height is displayed in units. I went through the built in getInfo() functions and I can’t seem to find any that extracts the scaled height.

Am I on the right track?

Antsushi,

you are nearly there!

Does this

h = getHeight();
toScaled( h );
name = getTitle();
getSelectionCoordinates( x, y );
toScaled( x, y );
tabDelText = "";
for ( i = 0; i < x.length; i++ ) {
tabDelText += "" + x[i] + "\t" + h - y[i] + "\n";
}

work for you?

HTH

Herbie

Herbie,

It did, thank you. I was incredibly close to this solution myself. Instead of creating a new toScaled for h, I attempted to add it to toScaled(x, y, h), which obviously didn’t work. And then I spent way too much time trying to come up with some other way to do it. I can’t believe that I didn’t think of trying to do it the way you did, it’s so simple.

Thank you, and I absolutely agree that I should learn coding ImageJ macros.

Best,

Antsushi.

1 Like