Clear Filters
Clear Filters

Hello Matlab specialist . I am seeking help I want to do Carotid artery segmentation and use fit ellipse to identify the edges but eliipse wont fit! please help

6 views (last 30 days)
%Carotid Artery Segmentation and Interpolation
%Read an image
I = imread('Image_1.tif');
Error using imread>get_full_filename
File "Image_1.tif" does not exist.

Error in imread (line 372)
fullname = get_full_filename(filename);
%Convert the image into grayscale and histogram equalization
grayimage = I(200:399, 450:699);
nbins = 25;
grayimage = adapthisteq(grayimage,'clipLimit',0.02,'Distribution','rayleigh');
%Apply contrast adjustment & median filtering
L = imadjust(grayimage); % enhance contrast
M = medfilt2(L, [3 3]); % apply median filter to reduce noise
%apply Guassian filter to the image and difussion filtering
N = imgaussfilt(M,2);
K = imdiffusefilt(N);
% Detect edges using Canny edge detection
BW = edge(K, 'canny', 0.6);
[J,rectout] = imcrop(BW);
figure, imagesc(J)
% Create a binary mask using the imbinarize function
threshold = graythresh(rectout); % compute threshold
mask = imbinarize(K, threshold);
% Identify the center of the carotid artery
[Gmag, Gdir] = imgradient(mask);
[maxGmag, ind] = max(Gmag(:));
[center_y, center_x] = ind2sub(size(Gmag), ind);
% Identify the radius of the carotid artery
edge_points = bwboundaries(mask);
figure, imagesc(BW)
% Fit an ellipse to the identified points
[x, y] = find(J);
ellipse_t = fit_ellipse(x, y);
X0 = ellipse_t.X0;
Y0 = ellipse_t.Y0;
a = ellipse_t.a;
b = ellipse_t.b;
R = ellipse_t.R;
theta_r = linspace(0,2*pi);
ellipse_x_r = X0 + a*cos( theta_r );
ellipse_y_r = Y0 + b*sin( theta_r );
rotated_ellipse = R * [ellipse_x_r;ellipse_y_r];
% Overlay the ellipse onto the original image
figure,
imshow(J);
hold on;
plot( rotated_ellipse(1,:),rotated_ellipse(2,:),'r' );
save([file_name '.mat'])
for i = 1: 50
figure(1)
hold on
plot3(i*ones(1,size(rotated_ellipse,2)),rotated_ellipse(1,:),rotated_ellipse(2,:),'.')
end
  3 Comments
Moksh
Moksh on 23 Aug 2023
Hi Cynthia,
I ran the code that you mentioned above and I am getting the following error:
I have used the defalut 'fit_ellipse' function and it does not have an 'R' parameter. So did you write a custom function for your need? As the code that fits the ellipse is getting skipped and only the base image is being plotted in the final output.
Could you provide me with the 'fit_ellipse' function that you are using?

Sign in to comment.

Answers (0)

Categories

Find more on Animation in Help Center and File Exchange

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!