Note that there are some explanatory texts on larger screens.

plurals
  1. POMatlab: Submatrix selection using meshgrid() matrices
    primarykey
    data
    text
    <p>I know there should be a simple (and faster!) solution to my Matlab indexing problem but my google-jutsu is coming up short and I can't figure it out... :'(</p> <p>I'm trying to apply a plastic deformation to an image using Lanczos resampling/filtering/whatever you want to call it.</p> <p>I need to get the image samples from <code>G</code> corresponding to the deformed points (which are in the format returned by meshgrid() but subsequently deformed), from the source image to do the interpolation. Unfortunately due to the deformation applied (sheer, translation, rotation, stretch), <code>G(a:b, a:b)</code> is not going to give the correct range of samples anymore...</p> <pre><code>G = imload('xxx'); [x,y] = meshgrid(a:b); % Applies an arbitrary plastic deformation % size(Qx) == size(x), size(Qy) == size(y) [Qx, Qy] = f(x,y, deformation); % This, There must be an easier way to do this!!! % By the way: Qx, and Qy are doubles, hence the floor() and I need to do % some other arithmetic too but that is irrelevant for now. G_samples = arrayfun(@(X,Y) G(Y,X), floor(Qx), floor(Qy)); </code></pre> <p>My main problem here is that this code is in the absolute innermost, time critical portion of my code and I'd like to have a faster way than the arrayfun... The line above stands for about 80% of my execution time. </p> <p>Thanks in advance!</p> <h2>Edit</h2> <p>@natan That's not the issue here, I need to to accomplish the following:</p> <pre><code>for y=a:b for x=a:b G_samples(y,x) = G(floor(Qx(x,y)), floor(Qy(x,y))); end end </code></pre> <p>I have ImageProcessing toolbox circa r2006a. </p> <h2>Solution</h2> <p>Not exactly as pretty as I wanted but still faster:</p> <pre><code>P = impixel(G, floor(Qx), floor(Qy)); G_samples = reshape(P(;,1), size(Qx)); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload