Problem with cell array and mat2gray

5 views (last 30 days)
Hi everyone i have written the next code that reads multiple images whose names start with specific numbers and then does some changes to those images
clc; clear;
outLoopValues = number;
for k = 1 : numel(outLoopValues)
index = outLoopValues(k);
outLoopValues2 = size;
for r = 1 : numel(outLoopValues2)
index2 = outLoopValues2(r);
thisBaseFileName = sprintf('%d.%d0.png', index2, index);
thisFileName = fullfile(folder, thisBaseFileName);
images{index2, index} = imread(sprintf('%d.%d0.png', index2, index));
I1{index2, index} = images{index2, index}(:,:,1);
Icrop{index2, index} = imcrop(I1{index2, index},[1 1 100 100]);
Inew = Icrop(~cellfun('isempty', Icrop));
inpsur1{index2, index}=double(Icrop{index2, index});
Idetrended=mat2gray(inpsur1');
I=uint8(255*Idetrended);
I1=imadjust(I);
I2 = medfilt2(I1,[3 3]);
z=I1;
end
end
but i get the next error:
Error using mat2gray
Expected input number 1, A, to be one of these types:
logical, uint8, uint16, uint32, int8, int16, int32, single, double
Instead its type was cell.
does anyone know how can i fix this?

Accepted Answer

Walter Roberson
Walter Roberson on 11 Sep 2022
Idetrended = cellfun(@mat2gray, inpsur1', 'UniformOutput', 0);
I = cellfun(@im2uint8, Idetrended, 'UniformOutput', 0);
I1 = cellfun(@imadjust, I, 'UniformOutput', 0);
I2 = cellfun(@(img) medfilt2(img, [3 3]), 'UniformOutput', 0);
Several of those steps can be combined if you do not have a use for the intermediate variables.
  7 Comments
Walter Roberson
Walter Roberson on 12 Sep 2022
Yes, you posted while I was composing my reply.
Walter Roberson
Walter Roberson on 12 Sep 2022
%one combined step
I2 = cellfun(@(rgbimg) mefilt2(imadjust(im2uint8(mat2gray(rgbimg))), [3 3]), inpsur1.', 'uniform', 0)

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!