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

조회 수: 1 (최근 30일)
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 CenterFile Exchange에서 Display and Exploration에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by