% this is a sample processing program demonstrates the two modes of % segmentation explained in the paper (one by one - Batch) %" Automatic Semantic Segmentation of Breast Tumors in Ultrasound ... % Images Based on Combining Fuzzy Logic and Deep Learning – A Feasibility Study " % by: Samir M. Badawy 1, Abd El-Naser A. Mohamed 2, Alaa A. Hefnawy 3, ... % Hassan E. Zidan 3, Mohammed T. GadAllah 3,*, Ghada M. El-Banby 1 % first you have to download MT_Small_Dataset from S1 in the paper or from % https://www.kaggle.com/mohammedtgadallah/mt-small-dataset % second you must download the eight CNNs used here from Ref. No. 8: % https://doi.org/10.1016/j.compbiomed.2020.104036 %======================================================================== clear ; close all; clc; cd('C:\Program Files\Polyspace\R2020b\bin\Processing_modes_Explanation'); % Select a CNN model nets = {'alexnet','unet','vgg16','vgg19','resnet18','resnet50','mobilenet','xception'}; choice = menu('Select a CNN model:',nets); % Load CNN for semantic segmentation load(fullfile('CNNs', sprintf("cnn_%s.mat",nets{choice}))); %========================================================================= %========================================================================= % Define reading and write locations for input images %------------------------------------------------------------------------- read_200_benign = ''; read_200_malignant = ''; read_200_fuzzy_benign = ''; read_200_fuzzy_malignant = ''; %========================================================================= % Define reading and write locations for Output images %------------------------------------------------------------------------- write_200_benign = ''; write_200_malignant = ''; write_200_fuzzy_benign = ''; write_200_fuzzy_malignant = ''; %========================================================================= % Now starting One by One processing mode for each 200 images as follow: %------------------------------------------------------------------------- % Benign 200 before fuzzy (original) for gg = 1:200 cd (read_200_benign); input = strcat ('benign_Adjusted (', num2str(gg),').png'); eval ('im = imread (input);'); imseg = semanticseg(im, net); imseg = double (imseg); imseg = mat2gray (imseg , [0 255]); output = strcat ('pixelLabel_', num2str (gg, '%03d'),'.png'); cd(write_200_benign); eval ('imwrite (imseg, output)'); end % Malignant 200 before fuzzy (original) for gg = 1:200 cd (read_200_malignant); input = strcat ('malignant_Adjusted (', num2str(gg),').png'); eval ('im = imread (input);'); imseg = semanticseg(im, net); imseg = double (imseg); imseg = mat2gray (imseg , [0 255]); output = strcat ('pixelLabel_', num2str (gg, '%03d'),'.png'); cd(write_200_malignant); eval ('imwrite (imseg, output)'); end % Benign 200 After fuzzy for gg = 1:200 cd (read_200_fuzzy_benign); input = strcat ('benign_Fuzzy_', num2str(gg, '%03d'),'.png'); eval ('im = imread (input);'); imseg = semanticseg(im, net); imseg = double (imseg); imseg = mat2gray (imseg , [0 255]); output = strcat ('pixelLabel_', num2str (gg, '%03d'),'.png'); cd(write_200_fuzzy_benign); eval ('imwrite (imseg, output)'); end % Malignant 200 After fuzzy for gg = 1:200 cd (read_200_fuzzy_malignant); input = strcat ('malignant_Fuzzy_', num2str(gg, '%03d'),'.png'); eval ('im = imread (input);'); imseg = semanticseg(im, net); imseg = double (imseg); imseg = mat2gray (imseg , [0 255]); output = strcat ('pixelLabel_', num2str (gg, '%03d'),'.png'); cd(write_200_fuzzy_malignant); eval ('imwrite (imseg, output)'); end %======================================================================================= %==================================================================================== % % Define the class names and their associated label IDs - for both % ground truth and predected output classNames = ["Cancer","Normal_Tissue"]; labelIDs = [2 1]; %======================================================================= % creating pixelLabelDatastores holding ground truth lables to starte % evaluating process %--------------------------------------------------------------- cd('C:\Program Files\Polyspace\R2020b\bin\Processing_modes_Explanation'); ground_Truth_benign_Dir = fullfile('GroungTruth','benign_ground'); ground_Truth_malignant_Dir = fullfile('GroungTruth','malignant_ground'); ground_Truth_benign = pixelLabelDatastore(ground_Truth_benign_Dir,classNames,labelIDs); ground_Truth_malignant = pixelLabelDatastore(ground_Truth_malignant_Dir,classNames,labelIDs); %========================================================================= % creating datastore holding for predected output lables from the semantic % segmentation process %------------------------------------------------------------------------- cd(''); % define the output location you have determined before for original benign and malignant segmented images original_benign_labels = pixelLabelDatastore('benign',classNames,labelIDs); original_malignant_labels = pixelLabelDatastore('malignant',classNames,labelIDs); cd('');% define the output location you have determined before for fuzzy benign and malignant segmented images fuzzy_benign_labels = pixelLabelDatastore('benign',classNames,labelIDs); fuzzy_malignant_labels = pixelLabelDatastore('malignant',classNames,labelIDs); %======================================================================================= % Quantitative evaluation of the prediction (segmented) results against the ground truth: %======================================================================================= original_benign = evaluateSemanticSegmentation(original_benign_labels,ground_Truth_benign); disp('this is for segmented benign -original '); fuzzy_benign = evaluateSemanticSegmentation(fuzzy_benign_labels,ground_Truth_benign); disp('this is for segmented benign by fuzzy'); original_malignant = evaluateSemanticSegmentation(original_malignant_labels,ground_Truth_malignant); disp('this is for segmented malignant -original '); fuzzy_malignant = evaluateSemanticSegmentation(fuzzy_malignant_labels,ground_Truth_malignant); disp('this is for segmented malignant by fuzzy'); %========================================================================= %========================================================================= %========================================================================= %========================================================================= %========================================================================= %========================================================================= % In case of Batch processing mode : % All the program above must be repeated except lines [ 40 to 105 ] % it will be replaced by the follow: %------------------------------------------------------------------------- % Benign 200 before fuzzy (original) cd (read_200_benign); % creating a datastore containing 200 images (Batch) imds_original_benign = imageDatastore(read_200_benign); % Excution of the semantic segmentation process on the Batch % datastore at one time Segmented = semanticseg(imds_original_benign,net,"WriteLocation",'write_200_benign'); % segmented original-benign % Malignant 200 before fuzzy (original) cd (read_200_malignant); % creating a datastore containing 200 images (Batch) imds_original_malignant = imageDatastore(read_200_malignant); % Excution of the semantic segmentation process on the Batch % datastore at one time Segmented = semanticseg(imds_original_malignant,net,"WriteLocation",'write_200_malignant'); % Benign 200 After fuzzy cd (read_200_fuzzy_benign); % creating a datastore containing 200 images (Batch) imds_fuzzy_benign = imageDatastore(read_200_fuzzy_benign); % Excution of the semantic segmentation process on the Batch % datastore at one time Segmented = semanticseg(imds_fuzzy_benign,net,"WriteLocation",'write_200_fuzzy_benign'); % Malignant 200 After fuzzy cd (read_200_fuzzy_malignant); % creating a datastore containing 200 images (Batch) imds_fuzzy_malignant = imageDatastore(read_200_fuzzy_malignant); % Excution of the semantic segmentation process on the Batch % datastore at one time Segmented = semanticseg(imds_fuzzy_malignant,net,"WriteLocation",'write_200_fuzzy_malignant');