How to display images based on the results from cell array?
1 view (last 30 days)
Show older comments
Greetings. I have several images stored in cell array (1x9 cell). Then I want to calculate the intensity percentage for all the images. Once I obtained all the answers, then I arranged all the data from high to low values. The question is how can I display the first three images that contained the highest percentage values?
nfiles2 = length(jpeg_files);
for k = 1:nfiles2
currentimage{k} = imread(fullfile(folder,jpeg_files(k).name));
newimg{k} = currentimage{k};
R{k} = newimg{k}(:,:,1);
G{k} = newimg{k}(:,:,2);
B{k} = newimg{k}(:,:,3);
redness{k} = double(R{k}) - max(double(G{k}), double (B{k}));
opim{k} = uint8(redness{k});
opim{k} = imfill(opim{k},'holes');
opim{k} = bwareaopen(opim{k},200);
R{k}(opim{k} == 0) = 0;
G{k}(opim{k} == 0) = 0;
B{k}(opim{k} == 0) = 0;
segimg{k} = cat(3,R{k},G{k},B{k});
calc1{k} = length(segimg{k}(segimg{k}~=0)); %number of pixel not black of img1
img2{k} = currentimage{k}-segimg{k}; % obtain image that consists of negative objects & background
calc2{k} = length(img2{k}(img2{k}~=0)); %number of pixel not black of img2
percentIntensity{k} = (calc1{k}/(calc1{k}+calc2{k}))*100; %calculate intensity percentage
[~,I] = sort(cell2mat(percentIntensity),'descend'); % arrange the data from high to low values
out = percentIntensity(I);
end
0 Comments
Answers (1)
Walter Roberson
on 25 Apr 2020
%where is currentimage defined?
nfiles2 = length(jpeg_files);
for k = 1:nfiles2
segimg{k} = imread(fullfile(folder,jpeg_files(k).name)); % read all the segmented images
calc1(k) = nnz(segimg{k}); %number of pixel not black of img1
img2{k} = currentimage{k}-segimg{k}; % obtain image that consists of negative cells & background
calc2(k) = nnz(img2{k}); %number of pixel not black of img2
percentTumorIntensity(k) = (calc1(k)/(calc1(k)+calc2(k)))*100; %calculate intensity percentage
end
[out,I] = sort(percentTumorIntensity,'descend'); % arrange the data from high to low values
for K = 1 : 3
subplot(1,3,K);
imshow(segimg{I(K)});
title(sprintf('% = %.2f', out(K)));
end
1 Comment
See Also
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!