# How to process each non-overlapped block of an image after it's sub-division?

1 visualización (últimos 30 días)
Mohsin Shah el 14 de Mzo. de 2018
Comentada: Image Analyst el 14 de Mzo. de 2018
My function sub-divides an image into non-overlapping blocks (each block is a cell matrix). I wonder how to process each block and then recombine them to make a processed image? Let's say I want to apply fast Walsh Hadamard transform (fwht2) on each block. Here is my function:
if true
function Blocks = imageBlock(I)
[m,n] = size(I);
Blocks = cell(m/8,n/8);
counti = 0;
for i = 1:8:m-7
counti = counti + 1;
countj = 0;
for j = 1:8:n-7
countj = countj + 1;
Blocks{counti,countj} = I(i:i+7,j:j+7);
end
end
end
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

Walter Roberson el 14 de Mzo. de 2018
cellfun() to process them. cell2mat() to recombine.
Have you considered using blockproc() instead of the steps you are taking now?
##### 1 comentarioMostrar -1 comentarios más antiguosOcultar -1 comentarios más antiguos
Mohsin Shah el 14 de Mzo. de 2018
Yes, I did consider blockproc() but I am making a mistake in using blockproc().
if true
fh = @fwht2d;
Ip = blcokproc(I, [8, 8], fh);
end
where fwht2d is a user-defined function. This code gives the following error: "BLOCKPROC encountered an error while evaluating the user-supplied function handle, FUN.
The cause of the error was:
Conversion to double from struct is not possible."

Iniciar sesión para comentar.

### Más respuestas (1)

Image Analyst el 14 de Mzo. de 2018
Use blockproc() and give it your function. It can be whatever you want. See attached examples.
##### 4 comentariosMostrar 2 comentarios más antiguosOcultar 2 comentarios más antiguos
Mohsin Shah el 14 de Mzo. de 2018
Editada: Mohsin Shah el 14 de Mzo. de 2018
It worked. Thank you, Walter Roberson. I wonder which answer to accept and which to vote. Both answers (from Image Analyst and Walter Roberson) have solved my problem.
Image Analyst el 14 de Mzo. de 2018
You can only accept one, but you can Vote for mine. Voting will also give the answerer reputation points. You can vote for as many as you want.

Iniciar sesión para comentar.

### Categorías

Más información sobre Neighborhood and Block Processing en Help Center y File Exchange.

### Community Treasure Hunt

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

Start Hunting!

Translated by