How can i plot the intensity of each row in an image?

This is what I have so far for my code. I was either going to use intensityValue or improfile but I don't really understand how it works.
I = imread('C:\Users\student\Pictures\2017-07-11\image.jpg');
warning('off', 'Images:initSize:adjustingMag');
%intensityValue= I (100,500);
%improfile
imshow(I);

Answers (2)

Hi Amelia,
I am assuming you have a 2-dimensional Image I. You can directly use the value in the image matrix to plot the intensity. For example:
I = imread('liftingbody.png');
x = 1:size(I,1);
y = 1:size(I,2);
[X,Y] = meshgrid(x,y);
plot3(X,Y,I)

5 Comments

I tried out this code and I get this message:
Error using plot3 Data cannot have more than 2 dimensions.
X = 1:size(Image,1);
Y = 1:size(Image,2);
[X,Y] = meshgrid(X,Y);
plot(X,Y)
Amelia, your image seems to be nxmx3 type. You can convert it to gray-scale to compute the "intensity" using Image = rgb2gray(Image);
Prashant Arora wrote "I am assuming you have a 2-dimensional Image I." . Your image is not 2D. You need to do rgb2gray to get intensity.
after using rgb2gray it still shows the same image as that of attached file

Sign in to comment.

surf( rgb2gray(YourRGBImage), 'edgecolor', 'none' )
colormap(gray(256))

12 Comments

This may be a stupid question but I haven't used matlab before. If i change it to grayscale, does that mean the image is now gray, would that affect the intensity profile.
the original is half black and half white.
and the attached image if what I get using the
code surf( rgb2gray(Image), 'edgecolor', 'none' )
colormap(gray(256))
is there a way to get it a 2d plot. Im trying to replicate an image that a spectrometer and iccd camera would give (plotting Intensity)
You can give the command
view(2)
to see it as 2D. However, the result should be the same (except perhaps rotated) as if you had just viewed the grayscale version of the image.
It would be easier for us to assist you in replicating a plot if we had a sample of the desired output.
My speculation is that what you are after is a plot showing either the mean or maximum intensity projection of the rows.
I = imread('C:\Users\student\Pictures\2017-07-11\image.jpg');
grey = rgb2gray(I);
subplot(1,2,1)
meanrowinten = mean(grey, 2);
plot(meanrowinten)
ylabel('mean row intensity')
subplot(1,2,2)
maxrowinten = max(grey, 2);
plot(maxrowinten)
ylabel('maximum row intensity')
"If i change it to grayscale, does that mean the image is now gray, would that affect the intensity profile." <=== Yes. But you have to say what you want. You can either have an RGB image with three separate channels for red, green, and blue, and plot just one of those channels. OR you can convert the whole thing to grayscale with rgb2gray() and plot that, either all lines superimposed, or with a display like surf() or waterfall(). You need to clarify what exactly you'd like if you could get exactly that (so we can stop guessing). So, in a perfect world, what would you like to see or end up with?
Sorry to clarify. The attached shows two images. one is an image of a experimental set up showing essentially what i am trying to do. A laser beam is going to be shined into a flame and a spectrometer is going to disperse the light into different wavelengths. I want to use Matlab to convert a jpg or any file to intensity (digital) file and plot intensity vs x axis along a particular column or row of pixels. the other photo shows what i want the graph to look like. it is plotting intensity vs. wavelength.
Lastly, I tried the code above and I think it works. The Plot looks like the image called trial2 attached. I was wondering if you could explain what each line of code is doing essentially. Thank you for the help.
Show your original image that you used to get the mean intensity.
Also, I believe the line should have been
maxrowinten = max(grey, [], 2); % Get max across columns within each row.
This was the original image. I chose it random to test out codes.
IA is correct, it should have been
maxrowinten = max(grey, [], 2); % Get max across columns within each row.
For setups like this, the setup is typically that there is a prism of some sort spreading the light, and that there is a band of monochrome CCD sensors. The position of each sensor is known, and the dispersion is known, so the frequency associated with each sensor is known.
Converting color photographs of color images into accurate intensity for scientific purposes is tricky. You need an accurate ICC color profile of the sensors used to take the photograph, and you have to worry about aliasing: any particular sensor reading might possibly be due to the "naive" interpretation, but it might also be associated with a brighter source being received less efficiently. And you have to take into account the properties of whatever the light is being reflected off of...
Last question.
meanrowinten= mean (grey,2); % mean (A,1)column mean (A,2)row
maxrowinten = max(grey, [], 2); % Get max across columns within each row.
If i changed the
meanrowinten= mean(grey, [],2);
It doesn't give me a graph of anything. Why doesn't it work similar to maxrowinten if I want to graph mean across columns within each row.
If i said mean (A,1) vs. mean (A,2). It takes into account Column whereas the (A,2) is specifically rows?
Thank you for all the help!
max() and mean() have different calling sequences. max(A, B) is element-by-element max(A(I,J), B(I,J)) unless B is empty, [], in which case max(A, []) is the same as max(A, [], 1) which is per-column maximum. max(A, [], 2) is per-row maximum.
mean(A,1) is per-column mean, and mean(A,2) is per-row mean.
how do i choose a single row in the image to analyze without using improfile?

Sign in to comment.

Categories

Asked:

on 12 Jul 2017

Commented:

on 12 Mar 2019

Community Treasure Hunt

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

Start Hunting!