Curvature detection from outlines of the binary image
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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.
0 Kommentare
Akzeptierte Antwort
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)
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)
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);
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu 3-D Volumetric Image Processing finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!