Filter löschen
Filter löschen

Curvature detection from outlines of the binary image

8 Ansichten (letzte 30 Tage)
DW
DW am 21 Nov. 2023
Kommentiert: DW am 22 Nov. 2023
This is my binary image. I used canny method to detect edge.
I want to identify these curvature(or spline), and plot them on the image.
(Left side and right side have different radius of curvatures.)
I searched several image processing techniques about this kind of problems, but I'm not sure where to start.
Any coment would be very helpful to me.
Thank you.

Akzeptierte Antwort

Image Analyst
Image Analyst am 21 Nov. 2023
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 = 16;
markerSize = 20;
%--------------------------------------------------------------------------------------------------------
% READ IN TEST IMAGE
folder = pwd;
baseFileName = 'DW 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 size
[rows, columns, numberOfColorChannels] = size(grayImage)
rows = 761
columns = 922
numberOfColorChannels = 3
if numberOfColorChannels == 3
grayImage = rgb2gray(grayImage);
end
% Convert to binary
binaryImage = grayImage > 128;
%--------------------------------------------------------------------------------------------------------
% Display the image.
subplot(1, 2, 1);
imshow(binaryImage, []);
impixelinfo;
axis('on', 'image');
title('Original Binary Image', 'FontSize', fontSize, 'Interpreter', 'None');
% Maximize window.
g = gcf;
g.WindowState = 'maximized';
g.Name = 'Demo by Image Analyst';
g.NumberTitle = 'off';
drawnow;
%--------------------------------------------------------------------------------------------------------
% Scan the image column by column
topRows = nan(1, columns);
for col = 1 : columns
t = find(binaryImage(:, col), 1, 'first');
if ~isempty(t)
% Only look at rows below row 103 and above 300.
if t >= 103 && t <= 300
topRows(col) = t;
end
end
end
subplot(1, 2, 2);
plot(topRows, 'b-', 'LineWidth', 2);
grid on
axis ij
% Fit a quadratic to the left half
goodColumns = ~isnan(topRows);
x = find(goodColumns);
y = topRows(goodColumns);
hold on;
polynomialOrder = 4;
coefficients = polyfit(x, y, polynomialOrder)
coefficients = 1×5
3.48880567786257e-09 -6.96896072580378e-06 0.00582763348942092 -2.28797501728093 443.86351083415
xFit = min(x) : max(x);
yFit = polyval(coefficients, xFit);
plot(xFit, yFit, 'r-', 'LineWidth',2);
xlabel('Column', 'FontSize',fontSize);
ylabel('Row (Line)', 'FontSize',fontSize);
caption = sprintf('Polynomial of order %d fitted through top rows', polynomialOrder);
title(caption, 'FontSize',fontSize);
  1 Kommentar
DW
DW am 22 Nov. 2023
Thank you very much.
The codes were very clear and I think I can modify this for further applications I want.
It was really helpful.
Thank you again!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by