How can I vectorize the imtranslate function?
Afficher commentaires plus anciens
As part of a larger code to estimate pair correlations, I want to translate an image, A (of size 512x512), by a random shift [rx ry].
J = imtranslate ( A, [-rx, -ry] );
followed by tiling this shifted image into a 3x3 larger image
C = repmat(J,3,3);
However, I want to perform this operation for a large number (~100) of random shift [-rx -ry]. Is there a way to vectorize these two steps to calculate J and C for ALL the set of random shifts in one shot? I have use the parfor routine with success, but was wondering if bsxfun can be used here.
Réponses (1)
I would do as below. In other words, I don't think there is anything to be gained by vectorizing the shifts, but if you do all the shifting first, the repmat-tiling can be done at the very end in a vectorized way (and it is recommendable),
Jstack=A;
Jstack(:,:,N)=0; %pre-allocate
parfor i=1:N
Jstack(:,:,i)=imtranslate(A,[-rx(i),-ry(i)]);
end
Cstack=repmat(Jstack,3,3);
If you can tolerate cyclic translation instead of the linear translation that imtranslate does, it may be possible to use bsxfun to implement the shifts as vectorized multiplications in the Fourier domain. It might be preferable for you to work in the Fourier domain anyway, since you say you are ultimately going to be doing something correlation-based. However, if the above is all you are going to do, I doubt Fourier methods will be faster.
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!