How to plot both horizontal and vertical profile for the same image?

6 ビュー (過去 30 日間)
Vanessa Phung
Vanessa Phung 2018 年 2 月 7 日
コメント済み: Loucif Riadh 2020 年 6 月 4 日
Hi. I'd like to plot a line profile across the beam and plot both horizontal and vertical profile on the same image. I manage to get one. I cannot plot the vertical profile and make it on the image together. Please give me any suggestion and help.Thank you.
% code
clc;close all;clear all;
img=imread('e_foil_spot.png');
img2=imcrop(img);
figure(1), imshow(img2);
c= improfile; hold on;d=improfile; % get the lime profile across
b=c';
% Plot the line profile on the same image
figure(1); imshow(img2); colormap('jet');
hold on; plot(b/(0.03*max(b)),'color', 'g','LineWidth', '10');
hold on; plot(d/(0.03*max(d)),'color', 'y','LineWidth', '10');
hold off

採用された回答

Image Analyst
Image Analyst 2018 年 2 月 7 日
編集済み: Image Analyst 2018 年 2 月 7 日
Try this:
grayImage = imread('moon.tif');
[rows, columns, numberOfColorChannels] = size(grayImage);
% Get the dimensions of the image.
% numberOfColorChannels should be = 1 for a gray scale image, and 3 for an RGB color image.
[rows, columns, numberOfColorChannels] = size(grayImage)
if numberOfColorChannels > 1
% It's not really gray scale like we expected - it's color.
% Use weighted sum of ALL channels to create a gray scale image.
grayImage = rgb2gray(grayImage);
% ALTERNATE METHOD: Convert it to gray scale by taking only the green channel,
% which in a typical snapshot will be the least noisy channel.
% grayImage = grayImage(:, :, 2); % Take green channel.
end
imshow(grayImage, []);
axis on;
verticalProfile = mean(grayImage, 2);
horizontalProfile = mean(grayImage, 1);
hold on;
% Plot horizontal profile.
x = 1 : columns;
amplitude = 2; % Scaling factor
y = rows - amplitude * horizontalProfile;
plot(x, y, 'r-', 'LineWidth', 2);
% Plot vertical profile.
y = 1 : rows;
amplitude = 1; % Scaling factor
x = columns - amplitude * verticalProfile; % To plot on RIGHT side
x = amplitude * verticalProfile; % To plot on LEFT side
plot(x, y, 'm-', 'LineWidth', 2);
If you'd rather, you can do
verticalProfile = grayImage(:, columnIndex);
horizontalProfile = grayImage(rowIndex, :);
where you specify the row and column where you want the profile to go through.
  2 件のコメント
Vanessa Phung
Vanessa Phung 2018 年 2 月 7 日
編集済み: Vanessa Phung 2018 年 2 月 7 日
Thank you very much. It works:)
Loucif Riadh
Loucif Riadh 2020 年 6 月 4 日
thank you verry image analyst, you are helping us a lot. we really pray for you

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDisplay and Exploration についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by