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

1 view (last 30 days)
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

Accepted Answer

KSSV
KSSV on 8 Mar 2017
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 Comments

Sign in to comment.

More Answers (0)

Categories

Find more on Denoising and Compression in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!