Question about Imaging functions

Hi,
I have done some measurement of a light source that I like to display in MATLAB. I want to look at the intensities for each pixel. But I don't understand some of the imaging functions. For example, my image is a 12 bit image.
imshow(my_image) shows the image with no visible coordinate system. Its black and white (the image is in gray scale). It looks very rough. Pixel info shows the coordinate system and the intensity is a value like 3.0E+30 . The label from figure shows [X,Y]:[1200 59], Index 304; [R,G,B]:[1 1 1].
image(my_image) shows just a blue image (I don't see the object ???). Index here is 0,2 to 0,006 something of magnitude.
image(my_image/max(my_image(:))*100) shows a blue, yellow and red image. I see my object. The red and yellow is where I have my object with certain intensity. Max intensity is something like 90, this label shows Index 90.19. I think "my_image/max(my_image(:))*100" is some kind of normalization.
  1. The question is what is the differencte between these three options?
  2. Which one is more valid to use in image processing?
The pixel intensitis is calibrated with measured total energy.
For example, I want to display the object in coordinate system showing the size in mrad (the angle). I am using the function imref2d, but when I plot this with imshow all the sudden the index is about 1.7 as max. I am also not sure the angle size is correct, but lets assume it is. I don't understand the "new" pixel value. It wouldn't allow me to plot this with image function.
xWorldLimits = [0 size(bild,2)*alphaPixel];
yWorldLimits = [0 size(bild,1)*alphaPixel];
image_mrad = imref2d(size(my_image),xWorldLimits,yWorldLimits);
hIM5 = imshow(my_image,image_mrad);
What am I doing wrong?
Thankful for any insights!

7 Comments

Before worrying about the display: What format is your image stored in, how is it imported into matlab and what class is your image once imported?
imshow (or imtool) are the proper way to look at images in matlab.
@Susan Lindecrantz PhD: please upload a representative image by clicking the paperclip button.
It looks very rough
I assume you are aware that computer displays are 8-bit (at most), so your image will have been discretised for display only.
the image is a .png file. Bit depth 16, saved as grayscale. No gain. Gamma = 1 or off.
[filename,filepath,filterindex] = uigetfile('*.*','Pick images to analyze','MultiSelect','on');cdata = imread([filepath filename]);
background = imread([filepath 'background.png']);
uploaded_image = double(cdata)-double(background);
Format png
FormatVersion []
Width 2048
Height 2048
BitDepth 16
ColorType grayscale
FormatSignature [137 80 78 71 13 10 26 10]
Colormap []
Histogram []
InterlaceType none
Transparency none
SimpleTransparencyData []
BackgroundColor []
RenderingIntent []
Chromaticities []
Gamma []
XResolution []
YResolution []
ResolutionUnit []
XOffset []
YOffset []
OffsetUnit []
SignificantBits 12
ImageModTime []
Title []
Author []
Description []
Copyright []
CreationTime []
Software []
Disclaimer []
Warning []
Source []
Comment []
OtherText []
No issue with the loading of the image.
How are you imshow'ing the image? And which image are you actually displaying? cdata or uploaded_image?
If you were imshow'ing cdata as you've loaded it, the pixel info tool should be showing intensities in the range [0 1023].
I see Index with up to 4.0E4 with 'cdata' in imshow. I usually imshow the uploaded_image. But then I create the my_image = my_image/max(my_image(:)*100).
I do some calculations of the intensity within different angles (circles). I am basically calibrating the image so one pixel intensity corresponds to a certain energy. I guess an normalized image like my_image/max(my_image(:)*100) would be fine with this.
sum_pixel = sum(sum(uploaded_image)) % whole image
calib_factor = energy/sum_pixel
uploaded_image = uploaded_image*calib_factor;
Im displaying uplaoded_image.
Hmm, why doesnt the following codes have the same index values?
%%PLOT data
figure(4)
my_image = uploaded_image/max(uploaded_image(:))*100;
hIM4 = image(my_image);
hold on
daspect([1 1 1]);
impixelinfo;
figure(5)
xWorldLimits = [0 size(my_image,2)*alphaPixel];
yWorldLimits = [0 size(my_image,1)*alphaPixel];
image_mrad = imref2d(size(my_image),xWorldLimits,yWorldLimits);
hIM5 = imshow(my_image,image_mrad);
hold on;
impixelinfo;
daspect([1 1 1]);
xlabel('alpha (mrad)')
ylabel('alpha (mrad)')
It should be the same. The last figure just change the coordinate to angle in imref2d.

Sign in to comment.

 Accepted Answer

why doesnt the following codes have the same index values
Because image and imshow don't behave the same way at all.
You should not be using image. It maps intensity to a colour map (which by default is parula) and the number of colours in that colour map will affect which intensity value maps to white.
The intensity that imshow maps to white depends on the class of the image. Your cdata image, as loaded is going to be uint16. imshow will associate intensity 65535 (maximum uint16 value to white). However, your image being original 12 bits, its maximum intensity will be 4095. You can tell imshow to use that range instead with:
imshow(cdata, [0 4095]);
Later on, you convert the image to double. For images of class double, matlab assumes the intensity range is [0 1]. Anything above 1 is considered the same as 1. Therefore your conversion would be better implemented as
uploaded_image = (double(cdata)-double(background)) / 4095; %to rescale to range 0-1
Instead what you did is rescale to the range 0-100. As said, for double images, imshow assumes that 1 and anything above is white. You can override that, again by specifying a custom display range:
my_image = uploaded_image/max(uploaded_image(:))*100;
imshow(my_image, [0 100]);
In all cases, impixelinfo should display the true intensity regardless of the display range.

More Answers (0)

Asked:

on 25 May 2018

Answered:

on 25 May 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!