Placement of Scale Bar is not optimal for images with non 1:1 aspect ratio

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Placement of Scale Bar is not optimal for images with non 1:1 aspect ratio

Stein Rørvik
When using the "Calibration Bar..." and "Scale Bar..." functions, the resulting position on the image is inconsistent for the two cases.

It seems that "Calibration Bar" uses symmetric margins of x = 1/50th of image width; y = 1/50th of image width
and "Scale Bar" uses a non-symmetric margin of x = 1/20th of image width; y = 1/20th of image height

I think this looks good for the Calibration Bar, but it often looks awkward for the Scale Bar.
The Scale Bar position in the corner will be asymmetric if the image aspect ratio is not 1:1.
Also, I think that the tighter margins of Calibration bar looks better on large images.

Perhaps these margins should be controllable with a setting somewhere, or the same method for setting Calibration Bar margins could be used for Scale Bar too, for consistent results?

Yes I know there we have the location=[At selection] option but that is only convenient to use for the upper left placement, as the resulting height and width of the scale bar is not known beforehand so you cannot easily use [At selection] in the other three corners of the image because you do not know the result width or height of the scalebar in pixels before its creation.

Please have a look at this demo macro to see what I mean:

newImage("Untitled", "8-bit black", 400, 400, 1);
AnnotateImage(12);

newImage("Untitled", "8-bit black", 2000, 2000, 1);
AnnotateImage(24);

newImage("Untitled", "8-bit black", 400, 2000, 1);
AnnotateImage(24);

newImage("Untitled", "8-bit black", 2000, 400, 1);
AnnotateImage(20);

//placement of Calibration Bar looks good in all images
//placement of Scale Bar looks good only in the smallest image with 1:1 aspect ratio

function AnnotateImage(fontsize) {
                run("Calibration Bar...", "location=[Upper Right] fill=White label=Black number=5 decimal=2 font=&fontsize zoom=1 overlay");
                //margin: x = 1/50th of width
                //margin: y = 1/50th of width
                run("Scale Bar...", "width=50 height=2 font=&fontsize color=Black background=White location=[Upper Left] overlay");
                //margin: x = 1/20th of width
                //margin: y = 1/20th of height
}

Stein


--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Placement of Scale Bar is not optimal for images with non 1:1 aspect ratio

Wayne Rasband-2
> On Sep 24, 2018, at 8:39 AM, Stein Rørvik <[hidden email]> wrote:
>
> When using the "Calibration Bar..." and "Scale Bar..." functions, the resulting position on the image is inconsistent for the two cases.
>
> It seems that "Calibration Bar" uses symmetric margins of x = 1/50th of image width; y = 1/50th of image width
> and "Scale Bar" uses a non-symmetric margin of x = 1/20th of image width; y = 1/20th of image height
>
> I think this looks good for the Calibration Bar, but it often looks awkward for the Scale Bar.
> The Scale Bar position in the corner will be asymmetric if the image aspect ratio is not 1:1.
> Also, I think that the tighter margins of Calibration bar looks better on large images.

The latest ImageJ daily build (1.52h9) now positions scale bars similar to the way calibration bars are positioned. It also fixes a bug that caused the default values in the Analyze>Tools>Scale Bar dialog to be altered by macros using the run("Calibration Bar…”,options) function.

-wayne

> Perhaps these margins should be controllable with a setting somewhere, or the same method for setting Calibration Bar margins could be used for Scale Bar too, for consistent results?
>
> Yes I know there we have the location=[At selection] option but that is only convenient to use for the upper left placement, as the resulting height and width of the scale bar is not known beforehand so you cannot easily use [At selection] in the other three corners of the image because you do not know the result width or height of the scalebar in pixels before its creation.
>
> Please have a look at this demo macro to see what I mean:
>
> newImage("Untitled", "8-bit black", 400, 400, 1);
> AnnotateImage(12);
>
> newImage("Untitled", "8-bit black", 2000, 2000, 1);
> AnnotateImage(24);
>
> newImage("Untitled", "8-bit black", 400, 2000, 1);
> AnnotateImage(24);
>
> newImage("Untitled", "8-bit black", 2000, 400, 1);
> AnnotateImage(20);
>
> //placement of Calibration Bar looks good in all images
> //placement of Scale Bar looks good only in the smallest image with 1:1 aspect ratio
>
> function AnnotateImage(fontsize) {
>                run("Calibration Bar...", "location=[Upper Right] fill=White label=Black number=5 decimal=2 font=&fontsize zoom=1 overlay");
>                //margin: x = 1/50th of width
>                //margin: y = 1/50th of width
>                run("Scale Bar...", "width=50 height=2 font=&fontsize color=Black background=White location=[Upper Left] overlay");
>                //margin: x = 1/20th of width
>                //margin: y = 1/20th of height
> }
>
> Stein

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Placement of Scale Bar is not optimal for images with non 1:1 aspect ratio

Stein Rørvik
Thanks,
now it looks much better.

The algorithm now seems to take both the width and the height into account when deciding the margin for the spatial scale bar, while the calibration bar strictly goes after the width. For narrow images, e.g. 400x2000, the scalebar position now looks better than the calibration bar position. Perhaps you can revise the calibration bar position to use the same algorithm you now have used for the scale bar?

Stein

-----Original Message-----
From: ImageJ Interest Group <[hidden email]> On Behalf Of Wayne Rasband
Sent: 27. september 2018 05:32
To: [hidden email]
Subject: Re: Placement of Scale Bar is not optimal for images with non 1:1 aspect ratio

> On Sep 24, 2018, at 8:39 AM, Stein Rørvik <[hidden email]> wrote:
>
> When using the "Calibration Bar..." and "Scale Bar..." functions, the resulting position on the image is inconsistent for the two cases.
>
> It seems that "Calibration Bar" uses symmetric margins of x = 1/50th
> of image width; y = 1/50th of image width and "Scale Bar" uses a
> non-symmetric margin of x = 1/20th of image width; y = 1/20th of image
> height
>
> I think this looks good for the Calibration Bar, but it often looks awkward for the Scale Bar.
> The Scale Bar position in the corner will be asymmetric if the image aspect ratio is not 1:1.
> Also, I think that the tighter margins of Calibration bar looks better on large images.

The latest ImageJ daily build (1.52h9) now positions scale bars similar to the way calibration bars are positioned. It also fixes a bug that caused the default values in the Analyze>Tools>Scale Bar dialog to be altered by macros using the run("Calibration Bar…”,options) function.

-wayne

> Perhaps these margins should be controllable with a setting somewhere, or the same method for setting Calibration Bar margins could be used for Scale Bar too, for consistent results?
>
> Yes I know there we have the location=[At selection] option but that is only convenient to use for the upper left placement, as the resulting height and width of the scale bar is not known beforehand so you cannot easily use [At selection] in the other three corners of the image because you do not know the result width or height of the scalebar in pixels before its creation.
>
> Please have a look at this demo macro to see what I mean:
>
> newImage("Untitled", "8-bit black", 400, 400, 1); AnnotateImage(12);
>
> newImage("Untitled", "8-bit black", 2000, 2000, 1); AnnotateImage(24);
>
> newImage("Untitled", "8-bit black", 400, 2000, 1); AnnotateImage(24);
>
> newImage("Untitled", "8-bit black", 2000, 400, 1); AnnotateImage(20);
>
> //placement of Calibration Bar looks good in all images //placement of
> Scale Bar looks good only in the smallest image with 1:1 aspect ratio
>
> function AnnotateImage(fontsize) {
>                run("Calibration Bar...", "location=[Upper Right] fill=White label=Black number=5 decimal=2 font=&fontsize zoom=1 overlay");
>                //margin: x = 1/50th of width
>                //margin: y = 1/50th of width
>                run("Scale Bar...", "width=50 height=2 font=&fontsize color=Black background=White location=[Upper Left] overlay");
>                //margin: x = 1/20th of width
>                //margin: y = 1/20th of height }
>
> Stein

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html