我的图像大小为128 * 128,我分为32 * 32个非重叠块,问题是我想要更改特定块或选择块的值(例如第一个或第三个...)并获取具有新值的块然后在我的图像中替换它。您是否知道如何获得修改了一个块的图像(不是全部)? 谢谢 这是一个带有小矩阵的例子
setInterval(function(){Property=value;},1000);
这就是我得到的
%*********************
A=magic(6) ; %%%%% matrix size 6*6
B=Block(A,2,2) ; % divide the matrix into 2*2 non-overlapping blocks
subblock=B{3} ; % Choose the 3rd block
new_block= 2*subblock; % change the block values by multipliying by 2
我提取第3块
A = 35 1 6 26 19 24
3 32 7 21 23 25
31 9 2 22 27 20
8 28 33 17 10 15
30 5 34 12 14 16
4 36 29 13 18 11
现在我乘以2:
sub_block=19 24
23 25
这是我的阻止功能:
new_block= 38 48
46 50
端 我想在矩阵A中替换这些值,但取决于块编号。我该怎么办?
答案 0 :(得分:1)
只需输入您要访问的行和列,例如
A(1:2,5:6)=A(1:2,5:6)*2
更通用,其中n是第n个列块,m是第m个行块,c是块宽度,r是块高度(在您的示例中) ,n = 3,m = 1,r = c = 2)
A(((m-1)*r+1):(m*r), ((n-1)*c+1):(n*c)) = any block of size(r,c)
答案 1 :(得分:1)
我不知道您的Block
函数,您实际上并不需要转换为单元格矩阵,但如果您确实需要,那么我会这样做:
A = magic(6);
[m,n] = size(A);
r=2; %// Desired number rows of blocks, m must be a multiple of r
c=2; %// Desired number cols of blocks, n must be a multiple of c
%// Create blocks (but as a 2D grid rather than a list)
B = mat2cell(A,r*ones(m/r,1), c*ones(n/c,1))
%// Manipulate a block
B(1,3) = {2*B{1,3}};
%// Convert back to a matrix
cell2mat(B)
我认为RobertStettler's answer是更好的方式,如果这是你要做的全部