curve fitting, basic fitting for irregular ,specific geometric shapes?

4 views (last 30 days)
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.
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

Accepted Answer

Image Analyst
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
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.
selim
selim on 1 Aug 2012
Edited: selim on 1 Aug 2012
thank you sir for everything . but i think i made my problem more complex considering that i can solve this using basic fitting. i should not have thought that i must solve it by basic fitting.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!