display of the intensity curve of the points
1 view (last 30 days)
Show older comments
hello everyone, I use this code to select points :
IM=imread('capture.jpg');
imshow(IM);
impixelinfo;
[xi,yi]=getpts
I want after the selection of the points, display a curve which contains the intensity of each point
0 Comments
Accepted Answer
Image Analyst
on 11 Apr 2021
Simply extract them
intensityProfile = zeros(1, length(xi), 'uint8');
for k = 1 : length(xi)
column = round(xi(k));
row = round(yi(k));
intensityProfile(k) = grayImage(row, column);
end
plot(intensityProfile, 'b-', 'LineWidth', 2);
3 Comments
Image Analyst
on 11 Apr 2021
Um, do you know that your image was called IM, not grayImage? I feel like IM is not a very descriptive name so use I'd recommend to use grayImage instead. Or try this if you're not sure what type the image is:
theImage = imread('peppers.png');
subplot(1, 2, 1);
imshow(theImage);
impixelinfo;
uiwait(helpdlg('Left click points. Right click the last one to finish'));
[xi,yi]=getpts
[rows, columns, numberOfColorChannels] = size(theImage);
if numberOfColorChannels == 3
message = sprintf('The image is RGB not gray scale');
uiwait(helpdlg(message));
intensityProfile = zeros(length(xi), 3, 'uint8');
else
intensityProfile = zeros(1, length(xi), 'uint8');
end
for k = 1 : length(xi)
column = round(xi(k));
row = round(yi(k));
intensityProfile(k, :) = theImage(row, column, :);
end
subplot(1, 2, 2);
if numberOfColorChannels == 3
plot(intensityProfile(:, 1), 'r-', 'LineWidth', 2);
hold on;
plot(intensityProfile(:, 2), 'g-', 'LineWidth', 2);
plot(intensityProfile(:, 3), 'b-', 'LineWidth', 2);
else
plot(intensityProfile, 'b-', 'LineWidth', 2);
end
grid on;
ylabel('Gray Scale', 'FontSize', 18);
More Answers (0)
See Also
Categories
Find more on Image Segmentation and Analysis 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!