Why is my code not working?

1 vue (au cours des 30 derniers jours)
Hardit Singh
Hardit Singh le 9 Déc 2019
%Hello!
Hi I am using matlab 2016 and I am trying to find the cup to disk ratio of the retina using matlabs image processing toolox. I have attached an image of an example image the program takes in. I get the error:
Insufficient number of outputs from right hand side of equal sign to satisfy assignment.
Error in final (line 77)
centers = stats.Centroid;
drishtiGS_004.png
[filename,filepath]=uigetfile({'*.png', '*.jpg'},'Select and image');
%Gets file from user
if isequal(filename,0)
disp('User selected Cancel')
else
disp(['User selected ', fullfile(filepath, filename)])
end
originalI = imread(strcat(filepath, filename));
figure
imshow(originalI);
title('Please crop the image');
%Displays the original image the user inputs.
[xpos, ypos] = ginput(1);
%Gets the x and y position from where the user clicks to crop the image.
title('Original Image');
width = 756;
height = 756;
%The dimensions of the new cropped image.
xLeft = xpos - width/2;
yBottom = ypos - height/2;
%Calculates the position of the top left corner of the crop and the bottom
%right corner of the crop
croppedI = imcrop(originalI, [xLeft, yBottom, width, height]);
%Crops the original image base of the top left corner, bottom right corner, and its
%width and height
figure
imshow(croppedI);
title('Cropped Image');
%Displays cropped image to the user
saturatedI = rgb2hsv(croppedI);
saturatedI(:,:,1)=saturatedI(:,:,3)*1.2;
saturatedI(saturatedI > 1)=1;
saturatedI=hsv2rgb(saturatedI);
%Saturates the cropped image by 20%
redChannel = saturatedI(:,:,1);
%Converts the saturated image to the redChannel
greenChannel = saturatedI(:,:,2);
%Converts the saturated image to the greenChannel
BWred = imclearborder(redChannel);
fill = imfill(BWred,'holes');
SE=strel('disk',6)
diskimage=imdilate(fill,SE)
BWgreen = imclearborder(greenChannel);
fill = imfill(BWgreen,'holes');
SE=strel('disk',6)
cupimage=imdilate(fill,SE)
figure
imshow(diskimage);
title('disk image');
figure
imshow(cupimage);
title('cup image');
BW=BWred;
CC = bwconncomp(BW);
numPixels = cellfun(@numel,CC.PixelIdxList);
[biggest,idx] = max(numPixels);
BW(CC.PixelIdxList{idx}) = 0;
filteredForeground=BW;
a = diskimage;
stats = regionprops(double(a),'Centroid','MajorAxisLength','MinorAxisLength');
centers = stats.Centroid;
diameters = mean([stats.MajorAxisLength stats.MinorAxisLength],2);
radii = diameters/2;
disp(radii);
figure,imshow(croppedI);
hold on
viscircles(centers, radii);
hold off

Réponse acceptée

Image Analyst
Image Analyst le 9 Déc 2019
You can't pass a double RGB image into regionprops. You must pass either
  1. a binary image
  2. a labeled image, gotten from bwlabel(), or
  3. a connected components object, gotten from bwconncomp(), like your "CC".
See my Image Segmentation Tutorial in my File Exchange

Plus de réponses (0)

Catégories

En savoir plus sur Modify Image Colors dans Help Center et File Exchange

Produits


Version

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by