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