I want to calcualate this without for loop

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

 Accepted Answer

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

More Answers (1)

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.

Categories

Community Treasure Hunt

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

Start Hunting!