Pixel to mm
Tamanna
Hi I am new in IGOR and have started learning with the simple codes. I am trying to write a code which converts pixel to millimeter. I have written the following. But when I am executing the code, I am getting 0. I don't know what is wrong with the code. Can anyone please help me? TIA
function conversion ()
variable a
a=0.26458 // 0.26458 pixel = 1 mm
Wave b, fx // b= total number of pixels in horizonatal axis
Make/o/N=10 fx // number of points in the range of fx
Setscale /I x 0,640, b //range of the pixels
SetScale /I x 0,150, fx
fx= a*b
print fx
end
variable a
a=0.26458 // 0.26458 pixel = 1 mm
Wave b, fx // b= total number of pixels in horizonatal axis
Make/o/N=10 fx // number of points in the range of fx
Setscale /I x 0,640, b //range of the pixels
SetScale /I x 0,150, fx
fx= a*b
print fx
end
I don't quite understand the purpose of that function and what b and fx represent, but if you want to scale image pixels to mm you can simple use SetScale:
Setscale/P x 0, 0.26458, "mm", img
Setscale/P y 0, 0.26458, "mm", img
newimage img
July 19, 2018 at 12:54 am - Permalink
I'm not quite clear what you want to do. I think the reason you get 0 is that you are making a wave called fx and nothing is in that wave.
There's two different ways you could do this and as I see it you are trying to both in your code. One way is that you have a wave that has discrete values for numbers of pixels (where let's say each row - p - relates to different images or different measurements). You can convert those values by dividing each point in that wave by a (not multiplying as you have written). The second way is that you have a wave which corresponds to values found at pixel locations. Here you'd want to scale each x value to be the correct distance. This means you can access values by referring to their x-value (in mm) rather than their point value (p).
Take a look in the help topics - find out what p and x represent in a wave. Then try and edit your code and ask another question if it's not clear.
July 19, 2018 at 12:55 am - Permalink
Thanks for the help. I fixed it.
July 20, 2018 at 02:55 pm - Permalink
For future forum readers, please post your fix.
This is also a traditional courtesy to those who have taken time to help you.
Thanks!
July 20, 2018 at 03:29 pm - Permalink