# How to display images based on the results from cell array?

4 次查看（过去 30 天）
Fahmi Akmal Dzulkifli2020-4-25
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
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

### 回答（1 个）

Walter Roberson 2020-4-25
%where is currentimage defined?
nfiles2 = length(jpeg_files);
for k = 1:nfiles2
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 个评论显示隐藏 无

Sir, I got this error message
Error using sort
Only one input argument is supported for cell arrays.
Error in HotSpot (line 74)
[out,I] = sort(percentTumorIntensity,'descend'); % arrange the data from high to low values
*** I have edited the coding to make it more clearly

### 类别

Find more on Organize and Deploy Model Advisor Checks 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!