How do I store a series of 5*5 arrays into a multidimensional array?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 :)
0 commentaires
Réponse acceptée
Sven
le 11 Fév 2013
Modifié(e) : Sven
le 11 Fév 2013
Bob, here's a fix to your loop:
Agray=imread('rice.png');
[ar,ac]=size(Agray);
v1=5;
v2=5;
r=ar-v1+1;
c=ac-v2+1;
noOfArrays=r*c;
k = zeros([v1,v2,noOfArrays], class(Agray));
currSliceNo = 0;
for i=1:r
for j=1:c
currSliceNo = currSliceNo+1;
k(:,:,currSliceNo)=(Agray(i:i+4,j:j+4));
end
end
Note that I added a preallocation which will speed things up substantially, and I'm referencing "currSliceNo" as the 3rd dimension to k, rather than "noOfArrays".
Keep in mind that depending on how you will implement your copy/move detection, there may be some much "nicer" ways than rebuilding a large stack of little image tiles. It looks like convolution of a sample 5-by-5 image could be performed over the whole image at once, which I image will be both quicker and much less likely to run into memory issues for very large images.
Plus de réponses (2)
the cyclist
le 11 Fév 2013
Modifié(e) : the cyclist
le 11 Fév 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.
0 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!