Problem with cell array and mat2gray

조회 수: 5 (최근 30일)
lena kappa
lena kappa 2022년 9월 11일
댓글: Walter Roberson 2022년 9월 12일
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?

채택된 답변

Walter Roberson
Walter Roberson 2022년 9월 11일
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
Walter Roberson
Walter Roberson 2022년 9월 12일
Yes, you posted while I was composing my reply.
Walter Roberson
Walter Roberson 2022년 9월 12일
%one combined step
I2 = cellfun(@(rgbimg) mefilt2(imadjust(im2uint8(mat2gray(rgbimg))), [3 3]), inpsur1.', 'uniform', 0)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by