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?

 Akzeptierte Antwort

Walter Roberson
Walter Roberson am 11 Sep. 2022

0 Stimmen

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 Kommentare

lena kappa
lena kappa am 11 Sep. 2022
Bearbeitet: lena kappa am 12 Sep. 2022
Thanks @Walter Roberson for your time but i get the following error:
Error using cellfun
Input #2 expected to be a cell array, was char instead.
Error in Untitled (line 29)
I2 = cellfun(@(img) medfilt2(img, [3 3]), 'UniformOutput', 0);
also what do you mean they can be combined ? how?
I think that it should be
I2 = cellfun(@(img) medfilt2(img, [3 3]), I1, 'UniformOutput', 0);
lena kappa
lena kappa am 12 Sep. 2022
but what do you mean by : Several of those steps can be combined if you do not have a use for the intermediate variables?
Thanks again @Walter Roberson have a nice day!
I2 = cellfun(@(img) medfilt2(img, [3 3]), I1, 'UniformOutput', 0);
lena kappa
lena kappa am 12 Sep. 2022
wait isn't this the exact same thing i wrote in the comment above?
Walter Roberson
Walter Roberson am 12 Sep. 2022
Yes, you posted while I was composing my reply.
%one combined step
I2 = cellfun(@(rgbimg) mefilt2(imadjust(im2uint8(mat2gray(rgbimg))), [3 3]), inpsur1.', 'uniform', 0)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by