MATLAB Answers

Steven
0

How to get INTENSITY along a spcific curve?

Asked by Steven
on 14 Jan 2014
Latest activity Commented on by Image Analyst
on 29 Dec 2018
Hi.
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
Steven

  0 Comments

Sign in to comment.

2 Answers

Answer by Ashish Uthama on 14 Jan 2014
 Accepted Answer

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

  5 Comments

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.
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.
IA, good catch. Voted for your answer.

Sign in to comment.


Answer by 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
subplot(2,2,1);
imshow(grayImage);
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);
subplot(2,2,2);
imshow(mask);
title('Mask Image', 'FontSize', fontSize);
% Find boudnaries and plot over original grayscale image.
boundaries = bwboundaries(mask);
numberOfBoundaries = size(boundaries, 1);
subplot(2,2,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
end
subplot(2,2, 3);
plot(profile);
grid on;
title('Profile', 'FontSize', fontSize);
xlabel('Distance', 'FontSize', fontSize);
ylabel('Gray Level', 'FontSize', fontSize);

  4 Comments

Show 1 older comment
No, you don't need improfile(). You can also vote for my answer to give me credit but you can only accept one answer.
plz i want circle, not ellipse
Did you try my code? There is nothing that says it can't be a circle. If you still need help, start a new thread.

Sign in to comment.