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

Home » Public Forums » archive » Re: Given many images, find bounding box
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: Given many images, find bounding box [message #17632] Fri, 05 November 1999 00:00 Go to next message
Dick Jackson is currently offline  Dick Jackson
Messages: 347
Registered: August 1998
Senior Member
Herbert wrote:

> I have many spatially seperated (but maybe overlapped) images patches
> which I would like to make a big mosaic image with them.
>
> For each of the patch, I have the coor. (lat, lon) of the upper left
> hand corner and the # of rows and # of cols. I would like to find the
> biggerest bounding box that will contain all the patches.
>
> Can anyone point me to any existing algorithm that will find this
> bounding box

This is pretty straightforward, but I have to make a few assumptions:

- you have four arrays (lat, lon, rows, cols) containing values
for each of your patches
- all four are measured in pixels
- 'lat' increases as you go up, 'lon' increases as you go to the right
(no wrapping at lat +/- 90 or lon +/- 180 here, do you need that?
My, that would be interesting...)
- you want the *smallest* bounding box that contains the patches

Then the four edges of that bounding box are:

left = Min(lon)
top = Max(lat)
right = Max(lon + cols - 1)
bottom = Min(lat - rows + 1)

Hope this helps!

Cheers,
-Dick

Dick Jackson Fanning Software Consulting, Canadian Office
djackson@dfanning.com Calgary, Alberta Voice/Fax: (403) 242-7398
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Re: Given many images, find bounding box [message #17727 is a reply to message #17632] Mon, 08 November 1999 00:00 Go to previous message
Dick Jackson is currently offline  Dick Jackson
Messages: 347
Registered: August 1998
Senior Member
[it seems that my first try at sending this message didn't get out,
reposting:]

>> This is pretty straightforward, but I have to make a few assumptions:
>>
>> - you have four arrays (lat, lon, rows, cols) containing values
>> for each of your patches
>> - all four are measured in pixels
>> - 'lat' increases as you go up, 'lon' increases as you go to the right
>> (no wrapping at lat +/- 90 or lon +/- 180 here, do you need that?
>> My, that would be interesting...)
>> - you want the *smallest* bounding box that contains the patches
>>
>> Then the four edges of that bounding box are:
>>
>> left = Min(lon)
>> top = Max(lat)
>> right = Max(lon + cols - 1)
>> bottom = Min(lat - rows + 1)

Herbert wrote:
> Hi Dick,
>
> Well, this is not correct, for example, if I havbe only one patch,
> the upper left hand corner has the coordinate (1,10) (lon, lat) and the
> box has lon_size = 6 and lat_size = 8
>
> then the expected answer should be:
> left = 1
> right 7
> top = 10
> bottom = 2
> but using your formular the answers would be:
> left = 1
> right 6
> top = 10
> bottom = 3

Clearly, if that's the answer you need, just remove the "+ 1" and "- 1" from
the calculations. I notice that your earlier use of 'cols' and 'rows' has
changed to lon_size and lat_size. If you are calculating precise
measurements of lat/lon, then of course these would be formulas to use:

left = Min(lon)
top = Max(lat)
right = Max(lon + lon_size)
bottom = Min(lat - lat_size)

From your original description using 'rows' and 'cols', I was working with
another assumption, that all these numbers refer to pixel locations and
sizes, and you would use the bounds in order to, say, draw a box that
includes all of them. In your example, I took it to mean the pixel at [1,10]
is at top-left of the patch, and the patch is 6x8 pixels, thus extending to
(counting fingers...) [6,3], *inclusive*. If you use my first calculations,
the lines will coincide with the outermost pixels all around. The new
calculations would give a box that coincides at top and left, but extends
one pixel beyond at right and bottom.

This distinction of pure-measurements vs. pixel-counting is surely one of
the greatest sources of off-by-one errors in all computing!

> Also, it will be nice some how if it could take care of the +/- degrees
> too...... seems tricky....

I believe the first tricky part is to precisely define the question.

--
Cheers,
-Dick

Dick Jackson Fanning Software Consulting, Canadian Office
djackson@dfanning.com Calgary, Alberta Voice/Fax: (403) 242-7398
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Re: Given many images, find bounding box [message #17795 is a reply to message #17632] Sat, 06 November 1999 00:00 Go to previous message
Dick Jackson is currently offline  Dick Jackson
Messages: 347
Registered: August 1998
Senior Member
>> This is pretty straightforward, but I have to make a few assumptions:
>>
>> - you have four arrays (lat, lon, rows, cols) containing values
>> for each of your patches
>> - all four are measured in pixels
>> - 'lat' increases as you go up, 'lon' increases as you go to the right
>> (no wrapping at lat +/- 90 or lon +/- 180 here, do you need that?
>> My, that would be interesting...)
>> - you want the *smallest* bounding box that contains the patches
>>
>> Then the four edges of that bounding box are:
>>
>> left = Min(lon)
>> top = Max(lat)
>> right = Max(lon + cols - 1)
>> bottom = Min(lat - rows + 1)

Herbert wrote:
> Hi Dick,
>
> Well, this is not correct, for example, if I havbe only one patch,
> the upper left hand corner has the coordinate (1,10) (lon, lat) and the
> box has lon_size = 6 and lat_size = 8
>
> then the expected answer should be:
> left = 1
> right 7
> top = 10
> bottom = 2
> but using your formular the answers would be:
> left = 1
> right 6
> top = 10
> bottom = 3

Clearly, if that's the answer you need, just remove the "+ 1" and "- 1" from
the calculations. I notice that your earlier use of 'cols' and 'rows' has
changed to lon_size and lat_size. If you are calculating precise
measurements of lat/lon, then of course these would be formulas to use:

left = Min(lon)
top = Max(lat)
right = Max(lon + lon_size)
bottom = Min(lat - lat_size)

From your original description using 'rows' and 'cols', I was working with
another assumption, that all these numbers refer to pixel locations and
sizes, and you would use the bounds in order to, say, draw a box that
includes all of them. In your example, I took it to mean the pixel at [1,10]
is at top-left of the patch, and the patch is 6x8 pixels, thus extending to
(counting fingers...) [6,3], *inclusive*. If you use my first calculations,
the lines will coincide with the outermost pixels all around. The new
calculations would give a box that coincides at top and left, but extends
one pixel beyond at right and bottom.

This distinction of pure-measurements vs. pixel-counting is surely one of
the greatest sources of off-by-one errors in all computing!

> Also, it will be nice some how if it could take care of the +/- degrees
> too...... seems tricky....

I believe the first tricky part is to precisely define the question.

--
Cheers,
-Dick

Dick Jackson Fanning Software Consulting, Canadian Office
djackson@dfanning.com Calgary, Alberta Voice/Fax: (403) 242-7398
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Re: Given many images, find bounding box [message #17821 is a reply to message #17632] Fri, 05 November 1999 00:00 Go to previous message
hhpt is currently offline  hhpt
Messages: 3
Registered: August 1999
Junior Member
Hi Dick,

Well, this is not correct, for example, if I havbe only one patch,
the upper left hand corner has the coordinate (1,10) (lon, lat) and the
box has lon_size = 6 and lat_size = 8

then the expected answer should be:
left = 1
right 7
top = 10
bottom = 2
but using your formular the answers would be:
left = 1
right 6
top = 10
bottom = 3

Also, it will be nice some how if it could take care of the +/- degrees
too...... seems tricky....

-- Herbert

> This is pretty straightforward, but I have to make a few assumptions:
>
> - you have four arrays (lat, lon, rows, cols) containing values
> for each of your patches
> - all four are measured in pixels
> - 'lat' increases as you go up, 'lon' increases as you go to the right
> (no wrapping at lat +/- 90 or lon +/- 180 here, do you need that?
> My, that would be interesting...)
> - you want the *smallest* bounding box that contains the patches
>
> Then the four edges of that bounding box are:
>
> left = Min(lon)
> top = Max(lat)
> right = Max(lon + cols - 1)
> bottom = Min(lat - rows + 1)
>
> Hope this helps!
>
> Cheers,
> -Dick
>
> Dick Jackson Fanning Software Consulting, Canadian Office
> djackson@dfanning.com Calgary, Alberta Voice/Fax: (403) 242-7398
> Coyote's Guide to IDL Programming: http://www.dfanning.com/
>
>


Sent via Deja.com http://www.deja.com/
Before you buy.
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Default font size for a widget
Next Topic: Re: Two widget questions

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

Current Time: Fri Oct 10 03:12:10 PDT 2025

Total time taken to generate the page: 0.00855 seconds