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

Home » Public Forums » archive » Re: adding subset image into larger one
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: adding subset image into larger one [message #70168] Tue, 23 March 2010 19:02 Go to next message
Suguru Amakubo is currently offline  Suguru Amakubo
Messages: 24
Registered: March 2010
Junior Member
Ah I see! That explains it so essentially its:

new_image[tr_point[0,a]:tr_point[0,a]+L-1,tr_point[1,a]:tr_p oint[1,a]
+L-1] = new_image[tr_point[0,a]:tr_point[0,a]
+L-1,tr_point[1,a]:tr_point[1,a]+L-1] + temp_image

thus just adding to the part of the new_image array. Sorry I was a bit
confused earlier.

One question though is that when I run this I was given a run time
error saying that I am out of range on the first cycle of the loop
(when I checked the coordinates are sane and is not out of range):

(Some changes were added to avoid out of range errors, unrelated to
above):

nn=n_elements(mc_point(0,*))

;for loop that runs through the array and places blocks on top of the
image
for kk=0L,nn-1 do begin
x0 = mc_point(0,kk)
y0 = mc_point(1,kk)

if (x0 ge size_of_image - L) or (y0 ge size_of_image - L) then begin

if x0 ge size_of_image -L && y0 ge size_of_image -L then begin

temp_image = new_image2[size_of_image -L: size_of_image-1,
size_of_image -L:size_of_image-1]

endif else if x0 ge size_of_image -L && y0 le size_of_image - L &&
y0 ge 0 then begin

temp_image = new_image2[size_of_image -L:size_of_image-1, y0:y0+L-1]

endif else if x0 le size_of_image -L and y0 ge size_of_image -L and
x0 ge 0 then begin

temp_image = new_image2[x0:x0+L-1 , size_of_image -
L:size_of_image-1]

endif

endif else begin

;extracting the block from the original image
temp_image = new_image2[mc_point[0,kk]:mc_point[0,kk]
+L-1,mc_point[1,kk]:mc_point[1,kk]+L-1]

;adding the subset to a 400x400 image
;The error occures here
new_image[tr_point[0,kk]:tr_point[0,kk]
+L-1,tr_point[1,kk]:tr_point[1,kk]+L-1] += temp_image

;adding an 30x30 array of 1s to a blank 400x400 image population
population[tr_point[0,kk]:tr_point[0,kk]
+L,tr_point[1,kk]:tr_point[1,kk]+L] += coverage_image

endelse
endfor

sorry about the text wrapping and thank you all for the help :)
Re: adding subset image into larger one [message #70169 is a reply to message #70168] Tue, 23 March 2010 18:01 Go to previous messageGo to next message
penteado is currently offline  penteado
Messages: 866
Registered: February 2018
Senior Member
Administrator
On Mar 23, 9:53 pm, Suguru Amakubo <sfa2...@googlemail.com> wrote:
> I am under the impression that
>
> new_image[tr_point[0,a]:tr_point[0,a] $
> +L-1,tr_point[1,a]:tr_point[1,a]+L-1] += temp_image
>
> will define the portion of new_image as temp_image (please tell me if
> I am making a critical mistake) :)

Yes, it is a critical mistake. You are not seeing the difference
between the operators (=) and (+=). As Jeremy said,

a+=b

means*

a=a+b

Which seems to be what you want.

(*) The two expressions do not mean the same when evaluating a has
side effects, which is not the case here.
Re: adding subset image into larger one [message #70170 is a reply to message #70169] Tue, 23 March 2010 17:53 Go to previous messageGo to next message
Suguru Amakubo is currently offline  Suguru Amakubo
Messages: 24
Registered: March 2010
Junior Member
Unfortunately if I do that the function of the line (I think) will
change.

I intend the line to add the subset on top of the bigger image in a
while loop and the definition of the temp_image is done on the
previous line.

The original code was like:

a=0
b=-1

;while loop that runs through the array and places blocks on top of
the image
while a LT n_elements(mc_point[0,*]) do begin

;extracting the block from the original image
temp_image = new_image2[mc_point[0,b+1]:mc_point[0,b
+1]+L-1,mc_point[1,a]:mc_point[1,a]+L-1]

;adding the subset to a 400x400 image
new_image = new_image[tr_point[0,a]:tr_point[0,a]
+L-1,tr_point[1,a]:tr_point[1,a]+L-1] + temp_image

;adding an 30x30 array of 1s to a blank 400x400 image
population
population = population[tr_point[0,a]:tr_point[0,a]
+L,tr_point[1,a]:tr_point[1,a]+L] + coverage_image

a=a+1
b=b+1

endwhile

So the temp_image (a 30x30 array) was added to new_image(400x400) and
ditto with population and coverage_image

I am under the impression that

new_image[tr_point[0,a]:tr_point[0,a] $
+L-1,tr_point[1,a]:tr_point[1,a]+L-1] += temp_image

will define the portion of new_image as temp_image (please tell me if
I am making a critical mistake) :)
Re: adding subset image into larger one [message #70171 is a reply to message #70170] Tue, 23 March 2010 17:29 Go to previous messageGo to next message
penteado is currently offline  penteado
Messages: 866
Registered: February 2018
Senior Member
Administrator
On Mar 23, 9:22 pm, wlandsman <wlands...@gmail.com> wrote:
> Just to be sure -- if you are really breaking this into two lines (and
> I am not just seeing text wrapping) then you need a continuation
> symbol $
>
>         new_image = new_image[tr_point[0,a]:tr_point[0,a] $
>    +L-1,tr_point[1,a]:tr_point[1,a]+L-1] += temp_image

There is that, but there is also a more serious issue. It should be:

new_image[tr_point[0,a]:tr_point[0,a] $
+L-1,tr_point[1,a]:tr_point[1,a]+L-1] += temp_image

He had two assignments in one line.
Re: adding subset image into larger one [message #70172 is a reply to message #70171] Tue, 23 March 2010 17:27 Go to previous messageGo to next message
Suguru Amakubo is currently offline  Suguru Amakubo
Messages: 24
Registered: March 2010
Junior Member
On 24 Mar, 00:22, wlandsman <wlands...@gmail.com> wrote:
> On Mar 23, 7:08 pm, Suguru Amakubo <sfa2...@googlemail.com> wrote:
>
>> yes this seems like a compilation error, I get the output below when I
>> compile it:
>
>> IDL> .COMPILE "C:\Users\kaizo\physics\block_shift.pro"
>
>>         new_image = new_image[tr_point[0,a]:tr_point[0,a]
>> +L-1,tr_point[1,a]:tr_point[1,a]+L-1] += temp_image
>
>> ^
>> Syntax error.
>
> Just to be sure -- if you are really breaking this into two lines (and
> I am not just seeing text wrapping) then you need a continuation
> symbol $
>
>         new_image = new_image[tr_point[0,a]:tr_point[0,a] $
>    +L-1,tr_point[1,a]:tr_point[1,a]+L-1] += temp_image
>
> Wayne

It unfortunately is text wrapping, on the actual code its one line.
Re: adding subset image into larger one [message #70173 is a reply to message #70172] Tue, 23 March 2010 17:22 Go to previous messageGo to next message
wlandsman is currently offline  wlandsman
Messages: 743
Registered: June 2000
Senior Member
On Mar 23, 7:08 pm, Suguru Amakubo <sfa2...@googlemail.com> wrote:
> yes this seems like a compilation error, I get the output below when I
> compile it:
>
> IDL> .COMPILE "C:\Users\kaizo\physics\block_shift.pro"
>
>         new_image = new_image[tr_point[0,a]:tr_point[0,a]
> +L-1,tr_point[1,a]:tr_point[1,a]+L-1] += temp_image
>
> ^
> Syntax error.

Just to be sure -- if you are really breaking this into two lines (and
I am not just seeing text wrapping) then you need a continuation
symbol $

new_image = new_image[tr_point[0,a]:tr_point[0,a] $
+L-1,tr_point[1,a]:tr_point[1,a]+L-1] += temp_image

Wayne
Re: adding subset image into larger one [message #70174 is a reply to message #70173] Tue, 23 March 2010 17:08 Go to previous messageGo to next message
Suguru Amakubo is currently offline  Suguru Amakubo
Messages: 24
Registered: March 2010
Junior Member
Thank you all for the reply.

yes this seems like a compilation error, I get the output below when I
compile it:

IDL> .COMPILE "C:\Users\kaizo\physics\block_shift.pro"

new_image = new_image[tr_point[0,a]:tr_point[0,a]
+L-1,tr_point[1,a]:tr_point[1,a]+L-1] += temp_image

^
Syntax error.
At: C:\Users\kaizo\physics\block_shift.pro, Line 58

population = population[tr_point[0,a]:tr_point[0,a]
+L,tr_point[1,a]:tr_point[1,a]+L] += coverage_image

^
Syntax error.
At: C:\Users\kaizo\physics\block_shift.pro, Line 61
2 Compilation error(s) in module BLOCK_SHIFT.

and here are the while loop that contains them (I do get runtime error
running the below but that I now know how to resolve it and will be
done soon) :

a=0
b=-1

;while loop that runs through the array and places blocks on top of
the image
while a LT n_elements(mc_point[0,*]) do begin

;extracting the block from the original image
temp_image = new_image2[mc_point[0,b+1]:mc_point[0,b
+1]+L-1,mc_point[1,a]:mc_point[1,a]+L-1]

;adding the subset to a 400x400 image
new_image = new_image[tr_point[0,a]:tr_point[0,a]
+L-1,tr_point[1,a]:tr_point[1,a]+L-1] += temp_image

;adding an 30x30 array of 1s to a blank 400x400 image population
population = population[tr_point[0,a]:tr_point[0,a]
+L,tr_point[1,a]:tr_point[1,a]+L] += coverage_image

a=a+1
b=b+1

endwhile

Again thank you very much for your help. :)

Suguru
Re: adding subset image into larger one [message #70179 is a reply to message #70174] Tue, 23 March 2010 11:21 Go to previous messageGo to next message
penteado is currently offline  penteado
Messages: 866
Registered: February 2018
Senior Member
Administrator
On Mar 23, 1:59 pm, Suguru Amakubo <sfa2...@googlemail.com> wrote:
> Unfortunately both of those codes seem to have given me compilation
> errors...
>
> Any ideas?
>
> p.s. For future reference please tell me what += does. :)

Can you give more details on what errors, and where? Is it really a
compilation error, or is it a runtime error? Each case has different
possibilities for the source of the error.

What jeanh wrote makes sense, though I would suggest using [] instead
of () in the array indices,

new_image[tr_point[0,a]:tr_point[0,a]+L-1,tr_point[1,a]:tr_p oint[1,a]
+L-1] += temp_image

so that tr_point does not get confused with a function call.
Re: adding subset image into larger one [message #70180 is a reply to message #70179] Tue, 23 March 2010 11:07 Go to previous messageGo to next message
Jeremy Bailin is currently offline  Jeremy Bailin
Messages: 618
Registered: April 2008
Senior Member
On Mar 23, 12:59 pm, Suguru Amakubo <sfa2...@googlemail.com> wrote:
> Hi thank you for the quick response. :)
>
> Unfortunately both of those codes seem to have given me compilation
> errors...
>
> Any ideas?
>
> p.s. For future reference please tell me what += does. :)

a op= b

is equivalent to

a = a op b

-Jeremy.
Re: adding subset image into larger one [message #70181 is a reply to message #70180] Tue, 23 March 2010 09:59 Go to previous messageGo to next message
Suguru Amakubo is currently offline  Suguru Amakubo
Messages: 24
Registered: March 2010
Junior Member
Hi thank you for the quick response. :)

Unfortunately both of those codes seem to have given me compilation
errors...

Any ideas?

p.s. For future reference please tell me what += does. :)
Re: adding subset image into larger one [message #70182 is a reply to message #70181] Tue, 23 March 2010 09:14 Go to previous messageGo to next message
jeanh is currently offline  jeanh
Messages: 79
Registered: November 2009
Member
On 23/03/2010 11:00 AM, Suguru Amakubo wrote:
> Hi I am currently trying to add a subset of image (30x30) into a
> larger image (400x400) in 2 different sinarios:
>
> 1) adding a 30x30 subset taken from a 400x400 image and adding it to
> another 400x400 image.
>
> and
>
> 2) adding a 30x30 subset image into a blank 400x400 image
>
> I have encountered problems in both cases. for case 1) I could not
> find anywhere the syntax of adding the subset into the correct
> position. I used:
>
> new_image = new_image[tr_point(0,a):tr_point(0,a)
> +L-1,tr_point(1,a):tr_point(1,a)+L-1] + temp_image
>
> where tr_point is an array that contains the coordinates of the
> subset to be added and L = 30, temp_image is the subset. But seems
> like the new image does not change.
>
> for 2) aside from the problem I have above when I run the code above
> with the blank image IDL seems to 'crop' the blank 400x400 image into
> a 30x30 image...
>
> Would anybody have a solution to this?
>
> Thank you in advance
>
> Suguru

Hi Suguru,
the problem is that you are indeed subsetting your original image,
"deleting" the reminders!
Try this:
new_image[tr_point(0,a):tr_point(0,a)+L-1,tr_point(1,a):tr_p oint(1,a)+L-1]
+= temp_image

or

new_blank_image[tr_point(0,a):tr_point(0,a)+L-1,tr_point(1,a ):tr_point(1,a)+L-1]
= temp_image

Jean
Re: adding subset image into larger one [message #70267 is a reply to message #70168] Tue, 23 March 2010 19:19 Go to previous message
penteado is currently offline  penteado
Messages: 866
Registered: February 2018
Senior Member
Administrator
On Mar 23, 11:02 pm, Suguru Amakubo <sfa2...@googlemail.com> wrote:
> One question though is that when I run this I was given a run time
> error saying that I am out of range on the first cycle of the loop
> (when I checked the coordinates are sane and is not out of range):
>         ;adding the subset to a 400x400 image
> ;The error occures here
>         new_image[tr_point[0,kk]:tr_point[0,kk]
> +L-1,tr_point[1,kk]:tr_point[1,kk]+L-1] += temp_image

Then it is just the same as

http://groups.google.com/group/comp.lang.idl-pvwave/browse_t hread/thread/f6dd6d90a31a604c
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Calculating the Exponential using IDL
Next Topic: Detecting whether a user-defined System Variable is in use

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

Current Time: Wed Oct 08 15:11:12 PDT 2025

Total time taken to generate the page: 0.00770 seconds