How to get INTENSITY along a spcific curve?

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

 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)

10 Comments

Thanks!
But how can I ask it to exactly draw a circle that way?
Thanks!
You could use imellipse:
im = imread('coins.png');
% manually create a circle
figure;
imshow(im);
h = imellipse();
% create a mask out of it
mask = createMask(h);
figure;
imshow(mask);
% thin it down
thinmask = bwmorph(mask,'remove',inf);
figure;
imshow(thinmask);
% extract all pixels along this profile
profile = im(thinmask); % logical indexing
plot(profile);
You could also experiment with the IMFINDCIRCLES function, and maybe also combining IMPROFILE with the above snippet.
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.
good morning guys!
how can i get the fourier transform of the above profile?
i mean in this code
im = imread('coins.png');
% manually create a circle
figure;
imshow(im);
h = imellipse();
% create a mask out of it
mask = createMask(h);
figure;
imshow(mask);
% thin it down
thinmask = bwmorph(mask,'remove',inf);
figure;
imshow(thinmask);
% extract all pixels along this profile
profile = im(thinmask); % logical indexing
plot(profile);
The fft of pixels in the mask would not make sense. Why do you think it would?
thank you for your answer!
so you think that the fft of the profile does not have a meaning?
how do you think i could extract more information out of the graph i get from the profile?
Correct, I don't. It's just the intensity around the ellipse. Why do you think the spatial frequencies of that are meaningful? Maybe they're just more or less constant, perhaps with a little noise - basically the surrounding gray level of the blob. What information do you want?
Please start your own question with your own image and code attached.
yeah youre write. thanks for your time!
have a nice day!

Sign in to comment.

More Answers (1)

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);

12 Comments

Steven
Steven on 14 Jan 2014
Edited: Steven on 15 Jan 2014
Thanks my dear Image Analyst Genius!
So no need for improfile in your method?
I will also try your code when I go to my office today.
But how can I change it here and accept your answer now?
Thanks.
Steven
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.
Hello,
this code works fine for me as long as I just have one boundary, but my image has many boundarys which I want to find the intensity value for. How can I rewrite the loop so it saves the values for all the boundarys?
Thanks a lot!
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.
Hi Image Analyst,
I simply want the intensity profile over a line, so If I replace the
h = imellipse()
with
h = imline()
then the code will still give the required result? Becase I happen to get symmetric profile when I do so.
Thank you
It should, though I don't know why you want to use imline() when improfile() will give you the profile more directly.
Hi! thank you so much for this, I would like to do imrect() for a rectangle rather than an ellipse. However when I do that I get a kind of weird symmetrical looking profile with two peaks where there should only be one peak (please see attached image).
Also can you please explain in more detail how the extract all pixels along this profile part works?
@Anna Schoonen, there is no attached image.
sorry I forgot to attach! here is the image.
@Anna Schoonen, please post this in a thread of your own rather than using Steven's 7 year old question.

Sign in to comment.

Categories

Find more on Read, Write, and Modify Image in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!