Search code examples
imagematlabloopsmatrixcell

Matlab: Apply an operation to each element of matrix


i have 100 image that I have read and store in a matrix of the form <128x128x100 Double> and I want to apply an operation on each image. how can I do? I have another matrix of the form <40x20 cell> witch contain 800 image and I want to do the same thing, ie applying an operation on each image. I do not know how to make a loop that carries it. thank you for your help


Solution

  • Assuming your function is in this form function imageOut = someFunction(imageIn):

    First case: (assuming I is a MxNxP matrix with P images, each MxN)

    O = cell2mat(cellfun(@someFunction, num2cell(I, [1 2]), 'UniformOutput', false))
    

    Second case: (assuming I is a MxN cell array, each cell contains an image)

    O = cellfun(@someFunction, I, 'UniformOutput', false)