curve fitting, basic fitting for irregular ,specific geometric shapes?
5 views (last 30 days)
Show older comments
i have a region. i want to detect this object with basic or curve fitting.
for example, i want to pass all the pixels on coordinate plane and do a fitting.
http://uploadpic.org/v.php?img=K3AAlYW0M8 from Image to coordinate plane it becomes http://uploadpic.org/v.php?img=UGXFCNWzaQ
i tried basic fitting but i failed. i was expecting something like that :
(i made up)
because it happens correctly as seen in this application : http://uploadpic.org/v.php?img=NbFaNr7if5
0 Comments
Accepted Answer
Image Analyst
on 29 Jul 2012
Edited: Image Analyst
on 30 Jul 2012
Did you try polyfit() and polyval()? What was your code? What was the error message? I did it and it seemed to work perfectly well:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
fontSize = 16;
% Read in selim's demo image.
folder = 'C:\Users\selim\Documents';
baseFileName = 'C54DlekrK51DuexHIM4AXxiL.jpg';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% File doesn't exist -- didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, '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
rgbImage = imread(fullFileName);
subplot(2, 1, 1);
imshow(rgbImage, []);
axis on;
title('Original Color Image (already cropped)', 'FontSize', fontSize);
set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.
% Get the magenta points. Subsample by a factor of 4.
redChannel = rgbImage(1:4:end,1:4:end, 1) > 128;
[rows columns] = size(redChannel);
subplot(2, 1, 2);
imshow(redChannel, []);
axis on;
title('Red Channel', 'FontSize', fontSize);
%-------------------------------------
% Main code starts here !!!!!
% Get all the x,y points
[y x] = find(redChannel);
% Plug into polyfit
orderOfPolynomial = 2;
coeffs = polyfit(x, y, orderOfPolynomial)
% Get the estimated fit and plot over the image.
xValues = 1 : columns;
fittedY = polyval(coeffs, xValues);
hold on;
plot(xValues, fittedY, 'b-', 'LineWidth', 3);
title('Red Channel with Fitted Curve', 'FontSize', fontSize);
5 Comments
Image Analyst
on 31 Jul 2012
So I guess the answer is no. If not, then tell me why I should put more effort into helping you some more considering what happened with my last attempt.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!