フィルターのクリア

How to process a 'function' that take inputs as blocks from two matrices

1 回表示 (過去 30 日間)
Abdul Gaffar
Abdul Gaffar 2020 年 8 月 31 日
コメント済み: Abdul Gaffar 2020 年 8 月 31 日
Suppose there are two matrices A and B of size 6 x 6 (small size for convenience). If there is a function say, mat which takes inputs 'a' and 'b' as bocks of size 3 x 3 from A and B respectively. For instance, if function mat adds the corresponding elements of blocks a and b, then how to process this function on both the images A and B using 'blockproc' (perhaps) or any other method.
Note: Actually, A and B are gray scale images, and the function mat embeds the pixels of block 'b' into block 'a' (by pixel difference technique).

採用された回答

Walter Roberson
Walter Roberson 2020 年 8 月 31 日
mat = @(a,b) double(a) + double(b);
%assuming that the matrices are perfect multiples of the block size:
BS = 3;
Ac = mat2cell(A, BS * ones(1,size(A,1)/BS), BS * ones(1,size(A,2))/BS, size(A,3));
Bc = mat2cell(B, BS * ones(1,size(B,1)/BS), BS * ones(1,size(B,2))/BS, size(B,3));
resultc = cellfun(mat, Ac, Bc);
result = cell2mat(resultc); %careful it is double not uint8
  3 件のコメント
Walter Roberson
Walter Roberson 2020 年 8 月 31 日
mat = @(a,b) double(a) + double(b);
%assuming that the matrices are perfect multiples of the block size:
BSvert = 3;
BShorz = 3;
Ac = mat2cell(A, BSvert * ones(1,size(A,1)/BSvert), BSvert * ones(1,size(A,2))/BSvert, size(A,3));
Bc = mat2cell(B, BShorz * ones(1,size(B,1)/BShorz), BShorz * ones(1,size(B,2))/BShorz, size(B,3));
resultc = cellfun(mat, Ac, Bc, 'uniform', 0);
result = cell2mat(resultc); %careful it is double not uint8
BS was taken as 3 instead of 3 x 3 because the same block size was used for horizontal and vertical.
In this version of the code I used different variables for the two so that you could (if you wanted) use a different horizontal and vertical block size.
Abdul Gaffar
Abdul Gaffar 2020 年 8 月 31 日
This works.
Thanks.
One more thing: Can functon blockproc be used here?

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by