Asked by Viron Gil Estrada
on 22 Mar 2018

I want to plot the intensity profile of this image. I tried using improfile but I don't really know how it works. Can anyone help?

Answer by Akira Agata
on 22 Mar 2018

Accepted Answer

Like this?

I = imread('Capture.PNG');

x = [0 size(I,2)];

y = [size(I,1)/2 size(I,1)/2];

c = improfile(I,x,y);

figure

subplot(2,1,1)

imshow(I)

hold on

plot(x,y,'r')

subplot(2,1,2)

plot(c(:,1,1),'r')

hold on

plot(c(:,1,2),'g')

plot(c(:,1,3),'b')

Akira Agata
on 22 Mar 2018

Thanks, I'm glad to hear that!

If you use grayscale image, improfile function returns N-by-1 vector. So you should change the last 4 lines by plot(c).

Viron Gil Estrada
on 22 Mar 2018

Thanks a lot! That's all I need.

Warid Islam
on 9 Jul 2019

Hi,

How can we plot the intensity profile of the same image along the vertical direction instead of the horizontal direction? Thank you.

Sign in to comment.

Answer by Akira Agata
on 9 Jul 2019

Hi Warid-san,

You can do it by the same way, like the following.

I = imread('Capture.PNG');

% Since size(I,2)/2 = 215.5, I have set the value '215' directly for x

x = [215 215];

y = [0 size(I,1)];

c = improfile(I,x,y);

figure

subplot(2,1,1)

imshow(I);

hold on

plot(x,y,'r')

subplot(2,1,2)

plot(c(:,1,1),'r')

hold on

plot(c(:,1,2),'g')

plot(c(:,1,3),'b')

Answer by Lorenzo Gentili
on 20 Aug 2019

Hi Akira,

I'm trying to obtain an intesity profile of the image below, but I need more than a line. I would like to have at least 5 vertical line in order to understand how the intesity vary in different point of the image ( lets say the 2 boundaries, the center and 2 point between the boundaries and the center). Is it possible to obtain an unique intensity profile that is the sum of 5 intesity profile obtained by the verical lines ?

Thank you for your help

Lorenzo

Image Analyst
on 20 Aug 2019

To get a mean vertical profile between two columns:

verticalProfile = mean(grayImage(:, column1:column2), 2);

To get a mean horizontal profile between two rows:

horizontalProfile = mean(grayImage(row1:row2, :), 1);

Lorenzo Gentili
on 20 Aug 2019

Thank you for your answer.

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 1 Comment

## Walter Roberson (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/389889-how-to-plot-intensity-profile-of-an-image#comment_548092

Sign in to comment.