clc
clear all;
p_size = 256;
o_image = imread('picture.jpg');
image1= imresize(o_image, [p_size, p_size]);
block_size = 8;
n = p_size/ block_size;
b_image = uint8(zeros(n,n,3));
for i=1:n
for j=1:n
b_image(i,j,:)= sum(sum(image1((i-1)*block_size+1:i*block_size,...
(j-1*block_size+1:j*block_size,:)))/(block_size*block_size);
end
end

 Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 29 Jun. 2015
Bearbeitet: Andrei Bobrov am 29 Jun. 2015

1 Stimme

try use variant with Image Processing Toolbox
image1= imresize(o_image, [256, 256]);
b_image = imfilter(image1,ones(block_size)/block_size^2);

Weitere Antworten (1)

Image Analyst
Image Analyst am 29 Jun. 2015

0 Stimmen

If you, unfortunately, don't have the Image Processing Toolbox and can't use Andrei's fine answer, you can use conv2() as an alternative.
b_image = conv2(double(image1), ones(block_size)/block_size^2, 'same');
Just be sure to cast your image to double (like I did), and make sure your image is a gray scale image, not a color image.

Kategorien

Mehr zu Convert Image Type finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by