I want to calcualate this without for loop
Show older comments
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
More Answers (1)
Image Analyst
on 29 Jun 2015
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
Find more on Convert Image Type in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!