Curvature detection from outlines of the binary image
8 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Image Analyst
2023-11-21
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);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 3-D Volumetric Image Processing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!