Image profile intensity for many pixels

조회 수: 3 (최근 30일)
Sara
Sara 2023년 1월 23일
댓글: Sara 2023년 1월 24일
Hi,
I am working in the images and I was taken the image profile for these images.
What I want to do is I want to take many pixels along the line segment. As you can see in the attched image, I took the imgae profile using improfile to plot the intensity along the selected line (black line). It seems to me that the line onle slected one pxiel vaule. I want to take many pixels in which cover the whole green circle (in the image) alnge the line profile.
[x,y] = ginput(); % for selection
[cx, cy, porifle, xi,yi] = improfile(x,y,image,x',y','bicubic'); % take the image profile
plot(cx',porifle,'k','LineWidth', 3); %to plot the intnesity along the line

채택된 답변

Image Analyst
Image Analyst 2023년 1월 23일
DON'T name your image "image" since that is the name of a built in function.
You can do
% Get profile along that line and plot it.
horizontalProfile = grayImage(row, :);
Full Demo below:
% Demo by Image Analyst
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 22;
markerSize = 40;
%--------------------------------------------------------------------------------------------------------
% READ IN IMAGE
folder = [];
baseFileName = 'cameraman.tif';
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% The file doesn't exist -- didn't find it there in that folder.
% Check the entire search path (other folders) for the file by stripping off the folder.
fullFileNameOnSearchPath = baseFileName; % No path this time.
if ~exist(fullFileNameOnSearchPath, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
% 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.
fprintf('It is not really gray scale like we expected - it is color\n');
% Extract the blue channel.
grayImage = rgb2gray(grayImage);
end
%--------------------------------------------------------------------------------------------------------
% Display the image.
subplot(2, 1, 1);
imshow(grayImage);
impixelinfo;
axis('on', 'image');
title('Original Gray Scale Image', 'FontSize', fontSize, 'Interpreter', 'None');
% Update 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)
% Maximize window.
g = gcf;
g.WindowState = 'maximized';
drawnow;
%--------------------------------------------------------------------------------------------------------
% Ask user to click a line.
uiwait(helpdlg('Click the line you want the profile of.'))
[x, y] = ginput(1);
row = round(y);
% Display line over image.
yline(row, 'Color', 'r', 'LineWidth', 2)
%--------------------------------------------------------------------------------------------------------
% Get profile along that line and plot it.
horizontalProfile = grayImage(row, :);
subplot(2, 1, 2);
plot(horizontalProfile, 'b.-', 'LineWidth', 2)
grid on;
caption = sprintf('Profile of line #%d', row);
title(caption, 'FontSize', fontSize)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Explore and Edit Images with Image Viewer App에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by