fit the found retina area with a second-order polynomial using least-square curve fitting
3 次查看(过去 30 天)
显示 更早的评论
How to create a quadratic fit curve with the code and image attached, I have already integrated [x y] ?
[filename, pathname] = uigetfile({'*.*'},'File Selector');
if ~isequal(filename,0)
fullname = strcat(pathname,filename);
I=imread(fullname);
else
msgbox('Ban chua chon anh?')
end
Id = size(I);
if length(Id) == 3
B0 = rgb2gray(I);
else
B0 = I;
end
B0 = imadjust(B0);
k1 = fspecial('gaussian', [5 5], 2.5);
Ic = imfilter(B0,k1);
figure(1),subplot(6,3,1), imshow(I);
title('anh goc');
figure(1), subplot(6,3,2), imshow(B0);
title('anh tang tuong phan');
figure(1), subplot(6,3,3), imshow(Ic);
title('anh bo loc');
% Threshold the image to make a binary image.
grayImage=Ic;
thresholdValue = 60;
binaryImage = grayImage > thresholdValue;
binaryImage = bwareafilt(binaryImage, 1);
figure(1),subplot(6,3,4), imshow(binaryImage, []);
title('anh voi nguong');
%loc trung vi
I_m = medfilt2(binaryImage,[5 5]);
figure(1),subplot(6,3,5), imshow(I_m);
title('anh loc trung vi');
%dong-mo hinh thai
se1 = strel("disk",30);
C1 = imclose(I_m, se1);
se = strel("disk",5); %tao cau truc hinh dia
C2 = imopen(C1, se);
figure(1),subplot(6,3,6), imshow(C2);
title('tai cau truc');
%Duong cong bac hai
CC = bwconncomp (C2);
[x,y]=cellfun(@(x) ind2sub(size(C2),x), CC.PixelIdxList, 'UniformOutput', false);
回答(1 个)
yanqi liu
2022-3-18
yes,sir,may i ask what is the target,the curve?such as
clc; clear all; close all;
I = imread('https://ww2.mathworks.cn/matlabcentral/answers/uploaded_files/930214/MH2.jpeg');
Id = size(I);
if length(Id) == 3
B0 = rgb2gray(I);
else
B0 = I;
end
bw = imbinarize(B0,'adaptive','ForegroundPolarity','dark','Sensitivity',0.99);
bw = bwareafilt(bw, 1);
[r,c] = find(bw);
p = polyfit(c,r,5);
x = linspace(min(c), max(c), 2e2);
y = polyval(p, x);
figure; imshow(I, []);
hold on;
plot(x,y,'r--','LineWidth',2);
5 个评论
yanqi liu
2022-3-22
clc; clear all; close all;
warning off all
I = imread('https://ww2.mathworks.cn/matlabcentral/answers/uploaded_files/930214/MH2.jpeg');
Id = size(I);
if length(Id) == 3
B0 = rgb2gray(I);
else
B0 = I;
end
bw = imbinarize(B0,'adaptive','ForegroundPolarity','dark','Sensitivity',0.99);
bw = bwareafilt(bw, 1);
[r,c] = find(bw);
p = polyfit(c,r,5);
xt = linspace(min(c), max(c), 2e2);
yt = polyval(p, xt);
figure; imshow(I, []);
hold on;
plot(xt,yt,'r--','LineWidth',2);
% origin method
B0 = imadjust(B0);
k1 = fspecial('gaussian', [5 5], 2.5);
Ic = imfilter(B0,k1);
figure(2),subplot(6,3,1), imshow(I);
title('anh goc');
figure(2), subplot(6,3,2), imshow(B0);
title('anh tang tuong phan');
figure(2), subplot(6,3,3), imshow(Ic);
title('anh bo loc');
% Threshold the image to make a binary image.
grayImage=Ic;
thresholdValue = 60;
binaryImage = grayImage > thresholdValue;
binaryImage = bwareafilt(binaryImage, 1);
figure(2),subplot(6,3,4), imshow(binaryImage, []);
title('anh voi nguong');
%loc trung vi
I_m = medfilt2(binaryImage,[5 5]);
figure(2),subplot(6,3,5), imshow(I_m);
title('anh loc trung vi');
%dong-mo hinh thai
se1 = strel("disk",30);
C1 = imclose(I_m, se1);
se = strel("disk",5); %tao cau truc hinh dia
C2 = imopen(C1, se);
figure(2),subplot(6,3,6), imshow(C2);
title('tai cau truc');
%Duong cong bac hai
CC = bwconncomp (C2);
[x,y]=cellfun(@(x) ind2sub(size(C2),x), CC.PixelIdxList, 'UniformOutput', false);
figure;
imshow(C2, []); hold on;
plot(xt,yt,'r--','LineWidth',2);
delX = -30;
delY = 0;
tras = [1 0 delX; 0 1 delY; 0 0 1];
[R,C] = size(C2);
C3 = zeros(R,C);
for i = 1 : R
for j = 1 : C
temp = [i; j; 1];
temp = tras * temp;
x = temp(1, 1);
y = temp(2, 1);
if (x <= R) && (y <= C) && (x >= 1) && (y >= 1)
C3(x, y) = C2(i, j);
end
end
end
figure;
imshow(C3, []); hold on;
plot(xt,yt,'r--','LineWidth',2);
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!