curve fitting, basic fitting for irregular ,specific geometric shapes?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Image Analyst
2012-7-29
编辑:Image Analyst
2012-7-30
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 个评论
Image Analyst
2012-7-31
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!