How do I store a series of 5*5 arrays into a multidimensional array?
Mostrar comentarios más antiguos
Hi people, I am new to this forum as well as MATLAB. As of now I'm working on copy-move forgery and i intend to do a 5*5 pixel comparison within the image. I want to store the values of every 5*5 array within the image into a multidimensional array but i'm not too sure how. Below is what i've come up with so far:
clear;
clf;
A=imread('file1.png');
Agray=rgb2gray(A);
[ar,ac]=size(Agray);
v1=5;
v2=5;
r=ar-v1+1;
c=ac-v2+1;
noOfArrays=r*c;
for i=1:r
for j=1:c
k(:,:,noOfArrays)=(Agray(i:i+4,j:j+4));
end
end
k
In which k is my supposed multidimensional array. Any help would be appreciated thank you :)
Respuesta aceptada
Más respuestas (2)
Image Analyst
el 11 de Feb. de 2013
0 votos
How about using mat2cell()?
the cyclist
el 11 de Feb. de 2013
Editada: the cyclist
el 11 de Feb. de 2013
In the line
k(:,:,noOfArrays)=(Agray(i:i+4,j:j+4));
you are alway writing to the same "plane" along the 3rd dimension of k, because noOfArrays is a constant. I expect you actually wanted to write to different planes, varying with i and j.
The simplest way to do that is probably to just have a counter for each pass through the loop.
Categorías
Más información sobre Resizing and Reshaping Matrices en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!