comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: shifting a mask over an image
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: shifting a mask over an image [message #82251] Mon, 26 November 2012 07:41
haikoley is currently offline  haikoley
Messages: 5
Registered: November 2012
Junior Member
On Monday, November 26, 2012 12:13:49 PM UTC+1, haik...@gmail.com wrote:
> Hi,
>
>
>
> I'm trying to move a mask over an image using the shift function. But I'm not sure if I really understood the description in the IDL help.
>
>
>
> Let's say I have a 10x10 mask and a 100x100 image. In this case I have to create an array with the same size as my image. It is filles with 0 and my mask. Then I start moving the mask inside that array (in x direction and y direction). But every time I do it with both direction, there is an error message telling me that I have an incorrect number of arguments. It works fine for one dimension, though.
>
>
>
> Has anyone an idea how I can shift in both directions?
>
>
>
> Btw, my code looks like this:
>
>
>
> for i=0, n-1 do begin
>
> for j=0, n-1 do begin
>
> result=shift(template, shift_x[i], shift_y[j])
>
> cor=where(max(correlate(result, image))
>
> endfor
>
> endfor
>
>
>
>
>
> thanks,
>
> max

Yes, it does work now, thank you very much.
Re: shifting a mask over an image [message #82258 is a reply to message #82251] Mon, 26 November 2012 04:21 Go to previous message
tom.grydeland is currently offline  tom.grydeland
Messages: 51
Registered: September 2012
Member
On Monday, November 26, 2012 12:13:49 PM UTC+1, haik...@gmail.com wrote:
> Hi,

[...]

> Has anyone an idea how I can shift in both directions?

The following works for me:

template = bytarr(8,8)
template[0:2,0:2] = 1
print, template
print, shift(template, 1, 2)

Does this work for you? If so, your problem lies elsewhere. You have not shown us how 'template' or 'shift_x' and 'shift_y' were generated.

--T
Re: shifting a mask over an image [message #82259 is a reply to message #82258] Mon, 26 November 2012 04:18 Go to previous message
Mats Löfdahl is currently offline  Mats Löfdahl
Messages: 263
Registered: January 2012
Senior Member
Den måndagen den 26:e november 2012 kl. 12:13:49 UTC+1 skrev haik...@gmail.com:
> Hi,
>
> I'm trying to move a mask over an image using the shift function. But I'm not sure if I really understood the description in the IDL help.
>
> Let's say I have a 10x10 mask and a 100x100 image. In this case I have to create an array with the same size as my image. It is filles with 0 and my mask. Then I start moving the mask inside that array (in x direction and y direction). But every time I do it with both direction, there is an error message telling me that I have an incorrect number of arguments. It works fine for one dimension, though.
>
> Has anyone an idea how I can shift in both directions?
>
> Btw, my code looks like this:
>
> for i=0, n-1 do begin
> for j=0, n-1 do begin
> result=shift(template, shift_x[i], shift_y[j])
> cor=where(max(correlate(result, image))
> endfor
> endfor

The shift operation should be fine - IF template is a 2D array. If the number of dimensions of template is not 2, you would get the error message you mention. Do a "help template" before you enter the loop.

But apart from that, your code looks funny:

* The "cor=..." line har three opening parenthesis but only two closing ones so you should get an error from that when you try to run it.

* Correlate() returns a scalar so the where(max()) business makes no sense.

* And if you are trying to find the location of the pattern in the mask within the image by maximizing the correlation with respect to the shifts, you want to collect the correlation values in an array and then find the location of the maximum after the loop has finished.

/Mats
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: SVN Toolkit - IDL8.2.1 Linux not working
Next Topic: repeat vs. while

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:14:27 PDT 2025

Total time taken to generate the page: 0.00439 seconds