MATLAB Answers

How to get INTENSITY along a spcific curve?

23 views (last 30 days)
Steven on 14 Jan 2014
Commented: Image Analyst on 20 Feb 2020
How can I get the intensity along a specific curve?
I mean for the following image, I want the intensity along the red circle. How to do so?
The original image is only the grayscale one and I have drawn the red one myself, so I know its data.
Shall I do so for the grayscale image or the binary one?
Thanks so much


Sign in to comment.

Accepted Answer

Ashish Uthama
Ashish Uthama on 14 Jan 2014
You could try using improfile, it will let you draw the cirle and then return the values along the profile.
Air code:
% number of points you want to sample the profile with
N = 100;
profileValues = improfile(N)


Show 2 older comments
Image Analyst
Image Analyst on 14 Jan 2014
Ashish, that doesn't give the pixels in order as you move along the circle. It goes column by column so it gives the top of the circle, then the bottom, then the top again, then the bottom again, and so on as you move across the circle columnwise.
Image Analyst
Image Analyst on 14 Jan 2014
Steven, I know you accepted this one, but beware: the profile is not sorted as you go along the perimeter like it is with my code. Just try them both and see.
Ashish Uthama
Ashish Uthama on 14 Jan 2014
IA, good catch. Voted for your answer.

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 14 Jan 2014
Try this code:
clc; % Clear the command window.
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 24;
% Read in image
grayImage = imread('tire.tif');
% manually create a circle
title('Original Grayscale Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Let user create ellipse.
h = imellipse();
% Create a mask out of it
mask = createMask(h);
title('Mask Image', 'FontSize', fontSize);
% Find boudnaries and plot over original grayscale image.
boundaries = bwboundaries(mask);
numberOfBoundaries = size(boundaries, 1);
hold on;
thisBoundary = boundaries{1};
x = thisBoundary(:,2);
y = thisBoundary(:,1);
plot(x, y, 'g', 'LineWidth', 2);
hold off;
% extract all pixels along this profile
for k = 1 : length(x)
profile(k) = grayImage(y(k), x(k)); % logical indexing
subplot(2,2, 3);
grid on;
title('Profile', 'FontSize', fontSize);
xlabel('Distance', 'FontSize', fontSize);
ylabel('Gray Level', 'FontSize', fontSize);


Show 5 older comments
Image Analyst
Image Analyst on 13 Feb 2020
Just call the code for every set of distinct (x, y), like call it for (xa, ya), and (xb, yb), and so on for however many different x and y vectors you have.
Steven on 20 Feb 2020
Hi Image Analyst,
I simply want the intensity profile over a line, so If I replace the
h = imellipse()
h = imline()
then the code will still give the required result? Becase I happen to get symmetric profile when I do so.
Thank you
Image Analyst
Image Analyst on 20 Feb 2020
It should, though I don't know why you want to use imline() when improfile() will give you the profile more directly.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!