how to divide rgb image into blocks using for loop and find the rgb value for each block

1 次查看(过去 30 天)
bs=8;
% M=zeros(96,96,3);
row=r/bs;
col=c/bs;
a=1;
k=0;
l=0;
b=1;
p=1;
noofp=96;
mR=zeros(768,768);
mG=zeros(768,768);
mB=zeros(768,768);
while(p<=noofp)
for i=1:row
for j=1:col
M{p}=re(8*k+1:8*a,8*l+1:8*b,:);
mR=M{p}(i,j,1);
mG=M{p}(i,j,2);
mB=M{p}(i,j,3);
d=[mR mG mB];
p=p+1;
l=l+1;
b=b+1;
end
k=k+1;
a=a+1;
l=0;
b=1;
% figure,imshow(M{p});
end

采纳的回答

KSSV
KSSV 2017-3-8
bs=8;
M=rand(768,768,3);
[r,c,p] = size(M) ;
row=r/bs;
col=c/bs;
mR=M(:,:,1);
mG=M(:,:,2) ;
mB=M(:,:,3) ;
idx = 1:bs:r+bs ;
pos = [idx(1:end-1)' idx(2:end)'-1] ;
iwant = zeros(bs,bs,row) ;
for i = 1:row
iwant(:,:,i) = mR(pos(i,1):pos(i,2),pos(i,1):pos(i,2)) ;
end
  7 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Denoising and Compression 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by