MATLAB Answers


How to read light intensity values on jpg image

I'm working on a project on fluorescence thermography. I am a beginner for matlab and I am looking for the matlab steps and command to import and read the fluorescence intensity values on gray scale (not color) images captured (in .jpg). These values are requred to interpret the temperature values at various points.

Any help for detailed steps is appreciated! Thanks.


3 Answers

Answer by Ling Fang Toh on 3 Jan 2013
 Accepted answer

Hi, I have tried various commands but what I get are some integer which seems like rgb values to me. I'm trying to look for precise intensity values that is shown in about 3 decimal places. Also, is it possible to read the values by simply placing my cursor over the image?


This is not an answer to your question is it? So it should have been an edit to your original question or a comment on Walter's question. To move the mouse around and see the pixel values, you need to use the command impixelinfo() in the Image Processing Toolbox.

It appears to me that the original JPEG file format did not support floating point values such as would be needed to have 3 decimal places. Either the data was scaled to 0-255 (or 0-65535) before it was written, or else you are using JPEG 2000.

To look at values by positioning with your cursor, go to the menu bar, and select Tools and from there, Data Cursor.

Answer by Walter Roberson
on 3 Jan 2013

FLreadings = imread('YourInputImageName.jpg');
if ndim(FLreadings) > 2
  error('Try again with a grayscale image')

Then for any particular point row R column C, FLreadings(R,C) will be the intensity reading as stored in the image.


on 3 Jan 2013

Providing the jpeg doesn't have gamma correction.

JPEG does not itself do gamma correction: it just works on the exact values passed to the JPEG creation software, and reads back as close to those values as the lossy compression permits.

on 3 Jan 2013

You are correct that it is not part of the JPEG algorithm. But we don't know what process generated the JPEG. Typical consumer software also does other things to make a picture presentable. Since they are "captured in jpeg" I can only assume it is not a custom scientific camera?

Answer by Ling Fang Toh on 3 Jan 2013

I would also like to seek some explanation for this command imhist(I)... I am uncertain of the error message stating "to be two-dimensional".

>> imhist(I) ??? Error using ==> iptcheckinput Function IMHIST expected its first input, I or X, to be two-dimensional.

Error in ==> imhist>parse_inputs at 275 iptcheckinput(a, {'double','uint8','logical','uint16','int16','single'}, ...

Error in ==> imhist at 57 [a, n, isScaled, top, map] = parse_inputs(varargin{:});


Evidently you didn't try Walter's code, where it would warn you if you tried to read in a colored image. You can't use imhist() on a color image. You need to save your original thermal image in the original monochrome matrix, not the pseudocolored (color mapped) RGB version of it.

Your image is not grayscale then. It might be RGB in which all three planes are identical, and thus be a Truecolor image that happens to consist entirely of grays. Try

I2 = FLreadings(:,:,1);

I don't know why but it seems like everyone who comes here and asks about thermal images has the pseudocolored image, unfortunately. Probably because the native format is a vendor proprietary floating point format where each pixel is the actual temperature in degrees Celsius, and people don't have MATLAB code to read those proprietary formats (like I do) so they just save data out as an 8 bit grayscale or colored bitmap image. But then all or most of the true actual temperature information is lost. Even if you have the color map, the best you can get is the grayscale image, not the actual temperatures. You'd need additional calibration information on what temperature got assigned to what gray level.

Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!