fit the found retina area with a second-order polynomial using least-square curve fitting

3 views (last 30 days)
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);
  3 Comments
Thanh Vu
Thanh Vu on 17 Mar 2022
I need make a quadratic fit curve for white pixel area. I am doing image preprocessing to perform optical coherence tomography image classification using SVM method. So I am wanting to fit the retinal region found by a quadratic polynomial using the least squares curve fit. I then plan to warp the entire retina approximately horizontally by shifting each image column by a distance according to the fit curve. But I am not sure how to get quadratic fit curve on OCT image. So please help me
Thanh Vu
Thanh Vu on 18 Mar 2022
I want to make a curve fit like the red line in the left image on the right image. That is, I want to convert the red fit curve to the right image. So what should I do? help me

Sign in to comment.

Answers (1)

yanqi liu
yanqi liu on 18 Mar 2022
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);
Warning: Polynomial is badly conditioned. Add points with distinct X values, reduce the degree of the polynomial, or try centering and scaling as described in HELP POLYFIT.
x = linspace(min(c), max(c), 2e2);
y = polyval(p, x);
figure; imshow(I, []);
hold on;
plot(x,y,'r--','LineWidth',2);
  5 Comments
Thanh Vu
Thanh Vu on 21 Mar 2022
Thanh you very much yanqui liu. can you help me move the pixels or column pixel on the image against the red fit curve, so that the fit curve is back to almost the same as the horizontal line? I appreciate your help for me. Thank you
yanqi liu
yanqi liu on 22 Mar 2022
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);

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!