how to divide an image into 4*4 blocks and find the mean of each block ?

we are doing our graduation project on depth map generation.we have read an coloured image and converted it into a grsay scale.next we have to divide the image into 4*4 blocks and find the mean of each block.

 Respuesta aceptada

Img = rand(640, 480); % Test data
Img = reshape(Img, 4, 160, 4, 120);
meanImg = sum(sum(Img, 1), 3) / 16;
meanImg = squeeze(meanImg)

4 comentarios

meanImg = sum(sum(Img, 1), 3) / 16; wat does this statement do??
maria
maria el 16 de En. de 2013
Editada: maria el 16 de En. de 2013
thanks a lot.. can u pls tell me how to find the mean of each 4*4 block after the following codes
clc;clear all;close all;
i=importdata('C:\Users\Public\Pictures\Sample Pictures\Koala.jpg'); Img=rgb2gray(i);
[r c]=size(Img);
x=r/4;y=c/4;
Img = reshape(Img, 4, x, 4, y);
meanImg = sum(sum(Img, 1), 3) / 16;
meanImg = squeeze(meanImg);
@Maria: This statement calculates the sum twice, at first along the 1st dimension, than along the 3rd dimension. You can test this step by step using a rand(8,8) matrix.
I do not understand, what you want to get. What does "group" exactly mean here?
how to find the differnce between all the adjacent elements in an array???

Iniciar sesión para comentar.

Más respuestas (2)

Using this
meanImg = cellfun(@(c) mean(c(:)), mat2tiles(rgb2gray(Img),[4,4]) );

2 comentarios

maria
maria el 16 de En. de 2013
Editada: maria el 16 de En. de 2013
i am not able to acess MAT2TILES fn and wat is 'c'?

Iniciar sesión para comentar.

imshow(blkproc(rgb2gray(I), round([size(I,1) size(I, 2)]/4), ...
@(x) mean2(x)*ones(size(x)) ))

Preguntada:

el 16 de En. de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by