Finding the edge of an image

4 次查看(过去 30 天)
Hello! I have an image, and I want to calculate the edge of it (as seen in red),. Then I want to take that edge and calculate the local min and max values of that edge. How would I go about doing this? Image is attached with and without annotation!
  4 个评论
Image Analyst
Image Analyst 2022-10-30
@Seejal Padhi did you overlook my answer below (scroll down)? Anything wrong with it?
Seejal Padhi
Seejal Padhi 2022-10-31
Thank you sm! It worked really well. I appreciate your help!

请先登录,再进行评论。

采纳的回答

Image Analyst
Image Analyst 2022-10-26
Try this:
% 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 = 'wr_image.png';
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)
%--------------------------------------------------------------------------------------------------------
% Display the image.
subplot(1, 3, 1);
imshow(grayImage);
impixelinfo;
axis('on', 'image');
title('Original Gray Scale Image', 'FontSize', fontSize, 'Interpreter', 'None');
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 = grayImage(:, :, 3);
end
% 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;
%--------------------------------------------------------------------------------------------------------
% Threshold the image to get the bright blobs.
% https://www.mathworks.com/matlabcentral/fileexchange/29372-thresholding-an-image?s_tid=srchtitle
lowThreshold = 31;
highThreshold = 255;
% [lowThreshold, highThreshold, lastThresholdedBand] = threshold(lowThreshold, highThreshold, grayImage)
mask = grayImage >= lowThreshold & grayImage <= highThreshold;
% Take largest blob only.
mask = bwareafilt(mask, 1);
subplot(1, 3, 2);
imshow(mask)
title('Binary Mask Image', 'FontSize', fontSize, 'Interpreter', 'None');
%--------------------------------------------------------------------------------------------------------
% Get the top row for each column
topRows = nan(1, columns);
for col = 1 : columns
thisColumn = mask(:, col);
% Find top row
t = find(thisColumn, 1, 'first');
if ~isempty(t)
topRows(col) = t;
end
end
% Now overlay it onto the image
subplot(1, 3, 3);
imshow(grayImage)
hold on;
plot(topRows, 'r-', 'LineWidth', 4)
title('Top Row in Red', 'FontSize', fontSize, 'Interpreter', 'None');
  6 个评论
Image Analyst
Image Analyst 2023-9-22
Great. I'll get you code this morning.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Image Processing Toolbox 的更多信息

产品


版本

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by