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
採用された回答
その他の回答 (1 件)
Image Analyst
2014 年 1 月 14 日
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 件のコメント
Image Analyst
2014 年 1 月 15 日
No, you don't need improfile(). You can also vote for my answer to give me credit but you can only accept one answer.
sang min sung
2018 年 12 月 29 日
plz i want circle, not ellipse
Image Analyst
2018 年 12 月 29 日
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.
Jennika Hammar
2020 年 2 月 12 日
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!
Image Analyst
2020 年 2 月 13 日
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
2020 年 2 月 20 日
Image Analyst
2020 年 2 月 20 日
It should, though I don't know why you want to use imline() when improfile() will give you the profile more directly.
Anna Schoonen
2021 年 6 月 28 日
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?
Image Analyst
2021 年 6 月 29 日
@Anna Schoonen, there is no attached image.
Anna Schoonen
2021 年 6 月 29 日
sorry I forgot to attach! here is the image. 

Image Analyst
2021 年 6 月 30 日
@Anna Schoonen, please post this in a thread of your own rather than using Steven's 7 year old question.
カテゴリ
ヘルプ センター および File Exchange で Image Arithmetic についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!