Open image, read block of pixels, average the intensity of the block, display average intensity matrix
조회 수: 1 (최근 30일)
이전 댓글 표시
How would one open an image, block image in say, 20x20 pixel blocks and then get the average of each 20x20 pixel block's intensity? Is the conversion of RGB to Grayscale required, or just good practice? I then would like to generate a matrix with those averages. Still learning MatLab so any help would be greatly appreciated.
댓글 수: 0
답변 (1개)
KALYAN ACHARJYA
2019년 6월 13일
편집: KALYAN ACHARJYA
2019년 6월 13일
Considering Gray Image, if not convert to grayscale then perform
im=imread('Image.jpg');
%.................^^ Change as per image name
[rows colm]=size(im);
block1=im(1:20,1:20);
%..here ^^ you can choose the block acccordingly
avg=mean(block1(:));
disp(avg);
댓글 수: 6
KALYAN ACHARJYA
2019년 6월 13일
편집: KALYAN ACHARJYA
2019년 6월 13일
%This code is just for undestand how to move the window (20x20) over image
% Not recomended for multiple use of for loops, look other approaches of block operation
im=imread('Image.jpg');
%.................^^ Change as per image name
[rows colm]=size(im);
k=1;
for i=1:20:rows-20
for j=1:20:colm-20
block(k)=im(i:i+19,j:19);
current_block=block(k);
avg=mean(current_block(:));
fprintf('The Block Number %d and Avg is: %f',k,avg);
k=k+1;
end
end
Try with 10x10 matrices as an example, you will get the idea.
참고 항목
카테고리
Help Center 및 File Exchange에서 Computer Vision with Simulink에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!