現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
Feature extraction in 300 images -MATLAB coding?
1 回表示 (過去 30 日間)
古いコメントを表示
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!
採用された回答
Image Analyst
2020 年 12 月 15 日
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 件のコメント
MARIA MALAKOPOULOU
2020 年 12 月 17 日
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
Image Analyst
2020 年 12 月 17 日
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.
MARIA MALAKOPOULOU
2020 年 12 月 17 日
Ι 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?)
Image Analyst
2020 年 12 月 17 日
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
2020 年 12 月 18 日
編集済み: MARIA MALAKOPOULOU
2020 年 12 月 18 日
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
2020 年 12 月 18 日
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?
Image Analyst
2020 年 12 月 18 日
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
2020 年 12 月 19 日
編集済み: MARIA MALAKOPOULOU
2020 年 12 月 19 日
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')
Image Analyst
2020 年 12 月 19 日
If your ProcessSingleDicomFile() function returns only 4 values in the theseResults vector, then just have 4 columns:
allResults = zeros(numberOfFiles, 4);
Image Analyst
2020 年 12 月 19 日
Like usual, : means "all" so "all columns" since it is the second index.
MARIA MALAKOPOULOU
2020 年 12 月 19 日
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?
Image Analyst
2020 年 12 月 19 日
You need to use allFileNames
thisFileName = fullfile(myfolder, allFileNames {k});
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Image Data Workflows についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
アジア太平洋地域
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)