Feature extraction in 300 images -MATLAB coding?

Hey! I have 300 medical images, which i want to read and export some features in order to make a excel file, which will contain 300 columns(300 images) and 4,5,6... rows(it depends how many features we have). After exporting this excel data, i want to play with some algorithms to find those who get the highest results. Any help? Thanks in advance!

 Respuesta aceptada

Image Analyst
Image Analyst el 15 de Dic. de 2020

0 votos

Code snippets to process a sequence of files are in the FAQ. In the middle of the for loop, call your function that analyzes the image and save the results to an array. Write back if you can't figure it out.

14 comentarios

I have this function:
function features= myf(k,a,b,f,g,disp,ca_max,ch_max,cv_max,cd_max)
%Scale to 512x512 since images are of higher resolution
a=imresize(a, [512 512]);
%RGB to gray
if size(a,3)==3
b=rgb2gray(a);
end
figure;
imshow(a);
title('Original Image')
%Noise removal by median filter
f=medfilt2(a);
figure;
imshow(f);
title('Noise removal by median filter')
%Determine threshold by Otsu's method
th=graythresh(f);
g=im2bw(f,th);
figure;
imshow(g);
title('Binarized Image (Otsu Method)')
%Resize image for Wavelet Transformation
g=imresize(a, [128 128]);
figure;
imshow(g);
title('Resized Image')
%Find wavelet coefficients using 2D Wavelet Transform
[cA,cH,cV,cD]=dwt2(g,'db1');
disp('---WAVELET FEATURES---');
%Calculate max value for approximation coefficient
disp('Approximation Coefficient (Max Value) :');
ca_max=max(mean(double(cA)));
disp((ca_max));
%Calculate max value for horizontal coefficient
disp('Horizontal Coefficient (Max Value) :');
ch_max=max(mean(double(cH)));
disp((ch_max));
%Calculate max value for vertical coefficient
disp('Vertical Coefficient (Max Value) :');
cv_max=max(mean(double(cV)));
disp((cv_max));
%Calculate max value for diagonal coefficient
disp('Diagonal Coefficient (Max Value) :');
cd_max=max(mean(double(cD)));
disp(mean(cd_max));
end
and this is my code in command line:( I get an error "Unrecognized function or variable 'a'". What am I doing wrong?)
myFolder = 'C:\Users\maroumal\Desktop\kathares';
% 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, '*.png'); % 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);
features= myf(k,a,ca_max,ch_max,cv_max,cd_max); %My function.
imageArray = imread(fullFileName);
imshow(imageArray);
drawnow;
end
Your function was called before you read in the image. And don't call it "a" - pick something more recognizable. So the four lines should be like this:
grayImage = imread(fullFileName);
imshow(grayImage);
drawnow;
features= myf(k, grayImage, ca_max,ch_max,cv_max,cd_max); %My function.
Ι correct everything you told me and now i have this error "Unrecognized function or variable 'ca_max'" and appears only one image of 300( or maybe stops in the first because finds the error?)
Since you compute it inside, there is no need to pass ca_max through the argument list. Remove it, both where you define the function and where you call it
features= myf(k,a,ch_max,cv_max,cd_max); %My function.
MARIA MALAKOPOULOU
MARIA MALAKOPOULOU el 18 de Dic. de 2020
Editada: MARIA MALAKOPOULOU el 18 de Dic. de 2020
I change many things in for loop and also in function, but i cannot find the result i want.
for k = 1 : length(theFiles)
baseFileName = theFiles(k).name;
fullFileName = fullfile(theFiles(k).folder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
greyImage = imread(fullFileName);
imshow(greyImage);
drawnow; % Force display to update immediately.
features= myf(k,greyImage);
end
and my function:
function features= myf(k,greyImage,b,f,th,g,disp)
%Scale to 512x512 since images are of higher resolution
greyImage =imresize(greyImage, [512 512]);
%RGB to gray
if size(greyImage,3)==3
b=rgb2gray(greyImage);
end
figure;
imshow(greyImage);
title('Original Image')
%Noise removal by median filter
f=medfilt2(greyImage);
figure;
imshow(f);
title('Noise removal by median filter')
%Determine threshold by Otsu's method
th=graythresh(f);
g=im2bw(f,th);
figure;
imshow(g);
title('Binarized Image (Otsu Method)')
%Resize image for Wavelet Transformation
g=imresize(greyImage, [128 128]);
figure;
imshow(g);
title('Resized Image')
end
It appears the first image which export from the function and after thas shows :
Now reading C:\Users\maroumal\Desktop\kathares\chest (1).png
Output argument "features" (and maybe others) not assigned during call to "myf".
Thank you so much for your time @image analyst :)
Image Analyst
Image Analyst el 18 de Dic. de 2020
features needs to be created by myf() because it returns it to the calling routine. Can you show me where it creates it? What line is that?
Give me an example please, I cannot understand.
function features= myf(k,greyImage,b,f,th,g,disp)
% assign a value to features.
features = 1;
% If you don't like that value, then what DO you like?
%Scale to 512x512 since images are of higher resolution
greyImage =imresize(greyImage, [512 512]);
%RGB to gray
if size(greyImage,3)==3
b=rgb2gray(greyImage);
end
figure;
imshow(greyImage);
title('Original Image')
%Noise removal by median filter
f=medfilt2(greyImage);
figure;
imshow(f);
title('Noise removal by median filter')
%Determine threshold by Otsu's method
th=graythresh(f);
g=im2bw(f,th);
figure;
imshow(g);
title('Binarized Image (Otsu Method)')
%Resize image for Wavelet Transformation
g=imresize(greyImage, [128 128]);
figure;
imshow(g);
title('Resized Image')
end
MARIA MALAKOPOULOU
MARIA MALAKOPOULOU el 19 de Dic. de 2020
Editada: MARIA MALAKOPOULOU el 19 de Dic. de 2020
thank you for the impromvent code! It works !!!!
I'm looking for a way to store the results in an array. I found an another comment of yours using this code:
filePattern = fullfile(myfolder, '*.png');
files = dir(filePattern);
allFileNames = {files.name}
allResults = zeros(numberOfFiles, 8); %HERE WHY I USE THE zeros? and the 8 for my case is the number 4( features) i got from the function?
for k = 1 : numberOfFiles
thisFileName = fullfile(myfolder, filenames{k});
theseResults = ProcessSingleDicomFile(thisFileName)
allResults(k, :) = theseResults;
end
% excel workbook from our template.
excelFileName = fullfile(pwd, 'Results.xlsx');
excelTemplateFilename = fullfile(pwd, 'ResultsTemplate.xlsx');
if isfile(excelTemplateFilename)
copyfile(excelTemplateFilename, excelFileName)
end
% Now transfer the data to the 'Results' sheet of our output workbook.
xlswrite(excelFileName, filenames, 'Results', 'A2')
xlswrite(excelFileName, allResults, 'Results', 'B2')
If your ProcessSingleDicomFile() function returns only 4 values in the theseResults vector, then just have 4 columns:
allResults = zeros(numberOfFiles, 4);
And in for loop what means the ":" in the (k , :) ?
Image Analyst
Image Analyst el 19 de Dic. de 2020
Like usual, : means "all" so "all columns" since it is the second index.
In this part i don't know what means but it ate my mind !
for k = 1 : numberOfFiles
thisFileName = fullfile(myfolder, filenames{k});
theseResults = ProcessSingleDicomFile(thisFileName)
allResults(k, :) = theseResults;
end
I have this error constantly:
"Brace indexing is not supported for variables of this type."
I have tried to change the most of the variables, that's why i asked yoy before for the ":", can help please?
You need to use allFileNames
thisFileName = fullfile(myfolder, allFileNames {k});

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Images en Centro de ayuda y File Exchange.

Preguntada:

el 15 de Dic. de 2020

Comentada:

el 19 de Dic. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by