Finding the edge of an image

3 ビュー (過去 30 日間)
Seejal Padhi
Seejal Padhi 2022 年 10 月 25 日
コメント済み: Image Analyst 2023 年 9 月 22 日
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 件のコメント
Carolina Vazquez
Carolina Vazquez 2023 年 9 月 21 日
Image Analyst
Image Analyst 2023 年 9 月 22 日
Great. I'll get you code this morning.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by