Login  Register

Re: Get the pixel Size

Posted by Michael Entrup on Feb 02, 2016; 9:12am
URL: http://imagej.273.s1.nabble.com/Get-the-pixel-Size-tp5015501p5015520.html

Hi Ben,

in your first mail you wrote about "my ImageJ Plugins" and that is why I
was assuming you will need information on how to get the pixel size in Java.

If you want to write a macro, the code from your last mail is nearly
everything you need. Just make sure "image1" is selected before running
the macro. If "image1" is the tile of the image, you can use this
modified version:

var x = getNumber("Enter a value for x", 1);
var unit, pixelwidth, pixelHeight;
selectWindow("image1");
getPixelSize (unit, pixelWidth, pixelHeight);
var x_cal = x;
if (unit=="microns"){
        x_cal = pixelWidth * x;
}
else IJ.log("No calibration");
IJ.log("x is "+ x_cal + unit);

To learn how to program macros have a look at [1], [2] and for a command
reference [3].

Best regards
Michael

[1]: http://imagej.net/Introduction_into_Macro_Programming
[2]: http://rsbweb.nih.gov/ij/developer/macro/macros.html
[3]: http://rsbweb.nih.gov/ij/developer/macro/functions.html


On 01.02.2016 14:45, BenDehap wrote:

> Hello Michael,
>
> First thank you for your answer, someone give me a simple way to resolve my
> problem as following :
>
>
> getPixelSize (unit, pixelWidth, pixelHeight);
> if (unit=="microns"){
> x=pixelWidth;}
> else exit ("No calibration");
>
> but i seen that the method you propose is widely used on forums.
> Would it be possible to show me an example of code using "x" for the value
> of the pixel witdh and "image1" for the name of my image.
>
> I don't know if you have the time to do it, but i'm a coding beginner and i
> feell a bit lost.
>
> Thanks anyway.
>
> Ben
>
>
> 2016-02-01 11:15 GMT+01:00 Michael Entrup [via ImageJ] <
> [hidden email]>:
>
>> Hi Ben,
>>
>> each ImagePlus [1] has a method called ``getCalibration()``. It returns
>> the Calibration [2] instance of the ImagePlus. The Calibration Object
>> contains all the methods you need. ``getUnit()`` returns a String to
>> check if the unit is µm. ``getX(double x)`` converts a pixel value into
>> a physical unit.
>>
>> Best regards
>> Michael
>>
>> [1]: http://rsb.info.nih.gov/ij/developer/api/ij/ImagePlus.html
>> [2]: http://rsb.info.nih.gov/ij/developer/api/ij/measure/Calibration.html
>>
>>
>> On 31.01.2016 20:37, BenDehap wrote:
>>
>>> Hello,
>>>
>>> I have a simple problem and reading different forums didn't help me to
>>> resolve it.
>>>
>>> I need for my ImageJ Plugins to attribute to a variable "x" the value of
>> the
>>> pixel size in "µm" used in my pre-calibrated "image1".
>>>
>>> It would really help me if someone can help me on this case.
>>>
>>> Thanks very much.
>>>
>>> Ben
>>>
>>>
>>>
>>> --
>>> View this message in context:
>> http://imagej.1557.x6.nabble.com/Get-the-pixel-Size-tp5015501.html
>>> Sent from the ImageJ mailing list archive at Nabble.com.
>>>
>>> --
>>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>>>
>>
>> --
>> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>>
>>
>> ------------------------------
>> If you reply to this email, your message will be added to the discussion
>> below:
>> http://imagej.1557.x6.nabble.com/Get-the-pixel-Size-tp5015501p5015507.html
>> To unsubscribe from Get the pixel Size, click here
>> <
>> .
>> NAML
>> <
http://imagej.1557.x6.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>>
>
>
>
>
> --
> View this message in context: http://imagej.1557.x6.nabble.com/Get-the-pixel-Size-tp5015501p5015510.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

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