Feature extraction of breast lesions
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Warid Islam
am 20 Aug. 2020
Kommentiert: Walter Roberson
am 21 Aug. 2020
Hello,
I am trying to extract features from a segmented breast lesion. However I am getting an error when I try to use the regionprops function. Please find the code below:
clc;clear;close all
% Specify the folder where the files live.
myFolder = 'C:\Users\morteza\Desktop\Udemy Courses\Deep Learning A-Z\P16-Convolutional-Neural-Networks (1)\Convolutional_Neural_Networks\Images_Malignant\training_set\Benign\Images';
% Check to make sure that folder actually exists. Warn user if it doesn't.
if ~isfolder(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s\nPlease specify a new folder.', myFolder);
uiwait(warndlg(errorMessage));
myFolder = uigetdir(); % Ask for a new one.
if myFolder == 0
% User clicked Cancel
return;
end
end
% Get a list of all files in the folder with the desired file name pattern.
filePattern = fullfile(myFolder, '*.jpg'); % Change to whatever pattern you need.
theFiles = dir(filePattern);
for k = 1 : length(theFiles)
baseFileName = theFiles(k).name;
fullFileName = fullfile(theFiles(k).folder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
% Now do whatever you want with this file name,
% such as reading it in as an image array with imread()
r = im2double((imread(fullFileName)));
try
r=rgb2gray(r);
end
J = imnoise(r,'salt & pepper',0.02);
c=medfilt2(J);
b= adapthisteq(c);
% b = medfilt2(r1);
hy = fspecial('sobel');
hx = hy';
Iy = imfilter(double(b), hy, 'replicate');
Ix = imfilter(double(b), hx, 'replicate');
gradmag = sqrt(Ix.^2 + Iy.^2);
L = watershed(gradmag);
Lrgb = label2rgb(L);
se = strel('disk', 20);
Io = imopen(b, se);
Ie = imerode(b, se);
Iobr = imreconstruct(Ie, b);
Ioc = imclose(Io, se);
Iobrd = imdilate(Iobr, se);
Iobrcbr = imreconstruct(imcomplement(Iobrd), imcomplement(Iobr));
Iobrcbr = imcomplement(Iobrcbr);
fgm = imregionalmax(Iobrcbr);
% figure
Y = imclearborder(fgm);
stats1 = regionprops(Y,'Area','Circularity','Solidity','Eccentricity', 'EquivDiameter','EulerNumber','MajorAxisLength','MinorAxisLength','Perimeter');
area=stats1.Area;
circularity=stats1.Circularity;
solidity=stats1.Solidity;
eccentricity=stats1.Eccentricity;
equivdiameter=stats1.EquivDiameter;
eulernumber=stats1.EulerNumber;
major=stats1.MajorAxisLength;
minor=stats1.MinorAxisLength;
perimeter=stats1.Perimeter;
p(k,:)=[area,circularity,solidity,eccentricity,equivdiameter,eulernumber,major,minor,perimeter];
I get the following error message:
Insufficient number of outputs from right hand side of equal sign to satisfy assignment.
Error in gf (line 84)
area=stats1.Area;
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 20 Aug. 2020
area = vertcat(stats1.Area);
circularity = vertcat(stats1.Circularity);
solidity = vertcat(stats1.Solidity);
eccentricity = vertcat(stats1.Eccentricity);
equivdiameter = vertcat(stats1.EquivDiameter);
eulernumber = vertcat(stats1.EulerNumber);
major = vertcat(stats1.MajorAxisLength);
minor = vertcat(stats1.MinorAxisLength);
perimeter = vertcat(stats1.Perimeter);
However, your line
p(k,:)=[area,circularity,solidity,eccentricity,equivdiameter,eulernumber,major,minor,perimeter];
is going to have problems. You are going to need to turn p into a cell array.
The difficulty you are having is that you are assuming that your Y only has a single region in it. Now, it might be the case that you want to use bwareafilt() to pick out only the largest of the regions, but unless you do something like that, you are going to be getting multiple regions.
6 Kommentare
Walter Roberson
am 21 Aug. 2020
No.
regionprops will find any region that exists, even just single pixel. If it returns empty information then the data you passed to it was empty or you passed Connected Component that was empty or you passed Label information to it that was empty.
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!