Why make rectangle command those not make the rectangle in appropriate location

I am using this command:

makeRectangle(BX, BY, Width, Height);
to make rectangle in specific place. The BX, BY, Width and Height are defined. The code makes the rectangle in different location.
Any idea why?


the command is supposed to make a rectangular selection with the upper-left corner at BX, BY. The coordinates are in pixel not scaled coordinates.

It seems to work fine, so I guess we will need to see your code (and maybe the image) to be able to say more.

Best regards,


which code and which image?

You mean the info I provided is not enough? This question applies to any image that when I use

makeRectangle(BX, BY, Width, Height);

the location and size of the rectangle is not the same as the pixel number. and my question is that how can I set it to be based on scale number?

Thanks for the reply but I think it is opposite. The coordinates are now in scaled not pixel.
How can I switch to pixel coordinate?

Does this macro produce the same rectangle on the two images if you use it?

run("AuPbSn 40 (56K)");
run("Duplicate...", " ");
run("Specify...", "width=300 height=206 x=150 y=103");
makeRectangle(150, 103, 300, 206);

in my case yes, it seems to work.

I think you have a problem of image calibration, but to test it it would have been easier to have one of your image.
If it is not possible, I could use one of mine with a calibration.

1 Like

this is the command in ImageJ Macro (the language I am supposing you are using)
getPixelSize(unit, pw, ph, pd);

now in unit you have the unit of measurement of the image (i.e. um)
and pw, ph are the size in unit of 1 pixel.

With this information you can pass from pixel to unit of length and viceversa.

makeRectangle wants pixel units.


run("Specify...", "width=17.30 height=13.18 x=8.65 y=6.59 slice=1 scaled");

permit you with the keyword argument “scaled” to pass directly calibrated data.

1 Like

Thanks for the reply. I think I know what the source of problem is and I have a general question. How can I choose which coordinate basis: pixel or calibrated?
How can I switch to pixel coordinate or pixel coordinate?

To calibrate an image I usually use:

run("Properties...", "channels=1 slices=1 frames=1 unit=um pixel_width=0.35 pixel_height=0.35 voxel_depth=0.35");

supposing for example 0.35 um per pixel the calibration of the image.

To change to pixel (loosing the calibration) I usually use:

run("Properties...", "channels=1 slices=1 frames=1 unit=pixel pixel_width=1 pixel_height=1 voxel_depth=1");

with the ImageJ Macro language.