Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
shift pixels in 1d array according to another 1d array

Subject: shift pixels in 1d array according to another 1d array

From: Toni

Date: 5 Oct, 2010 20:36:20

Message: 1 of 2

Hello!

Just wandering if there exists a command or such, which takes an input 1d array
inp = zeros(10,1);
inp(5,1) = 5;

then it takes another array, which contains the individual shifts to be applied:

shift = zeros(10,1);
%shift = ones(10,1)
shift(5,1) = -2;

Then the result would be, when using the shift array to shift the pixels in the inp array,
all zeros except result(3,1) = 5

So in the shift array in pixel location 5 with a value -2, means that the pixel in inp array at location 5 should be shifted -2 pixels and so on...!


And all this should be subpixel, so interpolation is needed. And the arrays are going to be quite large and complex.

I tried to do this with:

result = interp1(in,xx'+shift,'nearest');

but without any luck. also imtransform with TFORM does not seem to apply here...

Many thanks for any help and suggestions!

Subject: shift pixels in 1d array according to another 1d array

From: Sean

Date: 5 Oct, 2010 21:13:04

Message: 2 of 2

"Toni " <annihilaatio@yahoo.com> wrote in message <i8g284$cf3$1@fred.mathworks.com>...
> Hello!
>
> Just wandering if there exists a command or such, which takes an input 1d array
> inp = zeros(10,1);
> inp(5,1) = 5;
>
> then it takes another array, which contains the individual shifts to be applied:
>
> shift = zeros(10,1);
> %shift = ones(10,1)
> shift(5,1) = -2;
>
> Then the result would be, when using the shift array to shift the pixels in the inp array,
> all zeros except result(3,1) = 5
>
> So in the shift array in pixel location 5 with a value -2, means that the pixel in inp array at location 5 should be shifted -2 pixels and so on...!
>
>
> And all this should be subpixel, so interpolation is needed. And the arrays are going to be quite large and complex.
>
> I tried to do this with:
>
> result = interp1(in,xx'+shift,'nearest');
>
> but without any luck. also imtransform with TFORM does not seem to apply here...
>
> Many thanks for any help and suggestions!

I think you need to explain a few details a little further:
-If nothing replaces a point that has been shifted away it becomes 0, always?
-The new point is moved to a subpixel location, how do you interpolate that? Do you want the two adjacent points of that basin to be reassigned with the interpolation including the new central point?
-Will there ever be two shifts to the same basin or point? such as:
shift = [ 0 1.1 0 0 -1.8 0 1 0 -1]?
-If so how do you want to handle it?

There is no stock MATLAB function to my knowledge that does this. However, it should be doable with a loop one shift at a time once you figure out the hierarchy of shifts etc.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us