How to put name of images files on workspace ?
    5 ビュー (過去 30 日間)
  
       古いコメントを表示
    
i have this code to store the number of white pixels that multiple images have. i store it in count variable and it worked but i also want it to also put the file name of images on workspace instead of only showing the data of number of white pixels in variable count so i could see which number of white pixels each image have.
folder_nrml = ('/Users/*/Documents/MATLAB/regionbased_seg/cv/NORMAL');
file_nrml = dir(fullfile(folder_nrml, '*jpg'));
jumlah_file_nrml = numel(file_nrml);
training_data_nrml = zeros(jumlah_file_nrml);
count = [];
for k = 1:jumlah_file_nrml
    I = imread(fullfile(folder_nrml, file_nrml(k).name));
    BW1 = edge(I, 'canny');
    %%imshow(BW1);
    [m,n]= size(BW1);
    %%count = [];
    calc = 0;
    for i = 1 : m
        for j = 1 : n
            if BW1(i,j) == 1
                calc = calc+1;
            %%else
            end
        end
    end
    count = [count;calc];
    imwrite(BW1,sprintf('/Users/*/Documents/MATLAB/regionbased_seg/final/NORMAL/MASK_0%d.jpg',k));
end
here is how the data store on count variable :

2 件のコメント
  MarKf
      
 2023 年 1 月 3 日
				This is anyway another basic matlab operations question, so do take some time to look at the resources, I assure you it'd save time, and I do mean yours.
The name you want to add next to the numbers is a string, so you'd need a different kind of variable than double (just numbers). You could make a cell ( cell_count(k,:) = {file_nrml(k).name, calc}; no need to preallocate) or a table or fprintf what you need
採用された回答
  cr
      
 2023 年 1 月 3 日
        Initialise 
count = {};
 instead of count = [];
then replace the count update before imwrite() as
count(end+1,:) = {file_nrml(k).name,calc};
その他の回答 (1 件)
  Mathieu NOE
      
 2023 年 1 月 3 日
        hello 
I have not the Image Processing Tbx , so I cannot fully use your code , but I believe my suggestions should work 
first suggestion, no need for the two inner for loops to find the number of white pixel 
this can be done in one line without any for loop 
the second suggestio is to store the filename and the count result in a cell array so you have both infos 
folder_nrml = ('/Users/*/Documents/MATLAB/regionbased_seg/cv/NORMAL');
file_nrml = dir(fullfile(folder_nrml, '*jpg'));
jumlah_file_nrml = numel(file_nrml);
training_data_nrml = zeros(jumlah_file_nrml);
count = [];
for k = 1:jumlah_file_nrml
    filename = file_nrml(k).name;
    I = imread(fullfile(folder_nrml, file_nrml(k).name));
    BW1 = edge(I, 'canny');
%     %%imshow(BW1);
%     [m,n]= size(BW1);
    %%count = [];
%     calc = 0;
%     for i = 1 : m
%         for j = 1 : n
%             if BW1(i,j) == 1
%                 calc = calc+1;
%             %%else
%             end
%         end
    calc = numel(find(BW1>0)); % or == 1 ?
    out{k,1} = filename;
    out{k,2} = calc;
    imwrite(BW1,sprintf('/Users/*/Documents/MATLAB/regionbased_seg/final/NORMAL/MASK_0%d.jpg',k));
end
参考
カテゴリ
				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!



