curve fitting, basic fitting for irregular ,specific geometric shapes?
조회 수: 4 (최근 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!