output of fun is not a matrix the same size as the block in block proc

1 vue (au cours des 30 derniers jours)
Kasra Sadatsharifi
Kasra Sadatsharifi le 16 Déc 2020
Commenté : Ameer Hamza le 18 Déc 2020
Hello,
I am trying to divid my image into distinct block and perform a function on each one of them. The output of my function would be two column matrices of coordinates and with each iteration the number of coordinates will not be the same(different number of points with specific features in each block). What should I do to be able to stack the coordinates into a two column matrix at each iteration so at the end I have a bunch of XY coordinates?
Thank you

Réponses (1)

Ameer Hamza
Ameer Hamza le 16 Déc 2020
Modifié(e) : Ameer Hamza le 16 Déc 2020
You can create a cell array for saving data in each iteration and then stack them together at the end
xy_cell = cell(1,N); % it assumes you have N blocks
for i = 1:N
% calculate x and y coordinates
xy_cell{i} = [x y];
end
xy = vertcat(xy_cell{:})
  2 commentaires
Kasra Sadatsharifi
Kasra Sadatsharifi le 17 Déc 2020
thank you ameer for your answer but blockproc stack the output of each patch as anumeric array and returns a matrix at the end. I have tried using cells but it did not work since you cannot have any other outputs other thatn the one the function stacks up together.
Ameer Hamza
Ameer Hamza le 18 Déc 2020
In that case, blockproc() is not an appropriate function for you. You either need to use for loops or something like this
img = rand(100); % example matrix
C = mat2cell(img, 20*ones(1,size(img,1)/20), 20*ones(1,size(img,2)/20)); % divide image in blocks of 20x20
C_processed = cellfun(@fun, C, 'uni', 0); % fun the function you want to call on each block. It should return an nx2 matrix
xy = vertcat(C_processed{:});

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by