# problem after divide image

조회 수: 6 (최근 30일)
wissa amer 2013년 6월 10일
Hello all .. This code to divide the image into blocks, each block 4 * 4 pixels and then find the average of the values of pixels in each block and then put the new values in the image matrix (a) The problem : after storage and display picture shows me a white image why? and Storage in the matrix are not taken properly The value of the average for the first block stored in the last position of the new matrix (a)
if true
I = imread('4.png');
Range_Image=rgb2gray(imread('4.png'));
[m n]=size(Range_Image); Nbrx = floor(m./4);
Nbry = floor(n./4); Nd=1;
for i=1:Nbrx
for j=1:Nbry
Mat=Range_Image((i-1)*4+1:i*4,(j-1)*4+1:j*4);
sumpixel=sum(Mat(:));
avg= floor(sumpixel/16);
a(i,j)=avg;
% subplot(Nbrx,Nbry,Nd); imshow(Mat)
% Nd=Nd+1;
end
end
end

댓글을 달려면 로그인하십시오.

### 답변 (2개)

Iain 2013년 6월 10일
편집: Iain 2013년 6월 10일
Sounds like either your number format is saturating.
Cast the image as double or single before averaging.
Alternatively use "imagesc" instead of imshow.
##### 댓글 수: 2없음 표시없음 숨기기
wissa amer 2013년 6월 10일
thank you soo much ..
Iain 2013년 6월 11일
To cast it as double:
dbl_version = double( Range_Image );

댓글을 달려면 로그인하십시오.

Image Analyst 2013년 6월 10일
uint8 images clip at 255 so it you add up 16 uint8 pixels, chances are they will sum to more than 255 and so it will clip at 255. You need to cast to single or double first. Then, if you want values in the same range, you need to divide by 16. Either way, if you want to display it you'll have to use [] as the second argument to imshow(). You can cast back to uint8 if you want the averages to be uint8, like if you want to save the small images or something.
##### 댓글 수: 3이전 댓글 1개 표시이전 댓글 1개 숨기기
wissa amer 2013년 6월 10일
imshow(a,[]) i do that.. rigth or wrong
Image Analyst 2013년 6월 11일
That's right. But like I said, you need to make sure a is of the right type to handle a sum, like uint16 or double, or single.

댓글을 달려면 로그인하십시오.

### 카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

### Community Treasure Hunt

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

Start Hunting!

Translated by