# Forum

### Author Topic: Regions Alignment  (Read 7356 times)

#### alexrich

• Newbie
• Posts: 3
##### Regions Alignment
« on: April 07, 2014, 06:14:49 PM »
Hello there,

The regions/bounding boxes can be manipulated manually and made roughly the same size, but does any one know if there a way to make them exactly the same between two chunks?

Cheers,
Alex

#### Alexey Pasumansky

• Agisoft Technical Support
• Hero Member
• Posts: 14099
##### Re: Regions Alignment
« Reply #1 on: April 07, 2014, 06:17:42 PM »
Hello Alex,

Python scripts can be used to copy bounding box from one chunk to another.
Best regards,
Alexey Pasumansky,
Agisoft LLC

#### alexrich

• Newbie
• Posts: 3
##### Re: Regions Alignment
« Reply #2 on: April 07, 2014, 06:23:51 PM »
Hi Alex,

thanks for the quick reply. I was having a look at the python api manual, but couldn't work out what functions can do this, any one created a script to do this (im no the best with code) or more advice on what function to use?

Cheers,
Alex

#### Alexey Pasumansky

• Agisoft Technical Support
• Hero Member
• Posts: 14099
##### Re: Regions Alignment
« Reply #3 on: April 07, 2014, 06:35:08 PM »
Hello Alex,

Here's the sample code:
Code: [Select]
`import PhotoScandoc = PhotoScan.app.documentchunk = doc.chunks[0]region = chunk.regionT0 = PhotoScan.Matrix.diag((1, 1, 1, 1))if chunk.transform != None: T0 = chunk.transformR0 = region.rotC0 = region.centers0 = region.sizeC0.size = 4C0.w = 1chunk = doc.chunks[1]if chunk.transform != None: T = chunk.transform.inv() * T0else: T = T0 R = PhotoScan.Matrix( [[T[0,0],T[0,1],T[0,2]], [T[1,0],T[1,1],T[1,2]], [T[2,0],T[2,1],T[2,2]]]) scale = R.row(0).norm()R = R * (1/scale) region.rot = R * R0c = T * C0c = c / c[3] / 1.c.size = 3region.center = cregion.size = s0 * scale / 1. chunk.region = region `
This should work to copy the bounding box from chunk #1 to chunk #2. However, it's important that both of them are either unreferenced or referenced the same coordinate system.
Best regards,
Alexey Pasumansky,
Agisoft LLC

#### alexrich

• Newbie
• Posts: 3
##### Re: Regions Alignment
« Reply #4 on: April 07, 2014, 07:17:09 PM »
that's absolutely great thanks. been trying for ages.

Cheers,
Alex

#### Claude

• Newbie
• Posts: 23
##### Re: Regions Alignment
« Reply #5 on: February 05, 2015, 11:18:07 PM »
Hello,
Please would you update this script for new API. It desn't work in newest version of agisoft.

Best wishes

#### Alexey Pasumansky

• Agisoft Technical Support
• Hero Member
• Posts: 14099
##### Re: Regions Alignment
« Reply #6 on: February 06, 2015, 10:07:17 AM »
Hello Claude,

I think it should be the following:
Code: [Select]
`import PhotoScandoc = PhotoScan.app.documentchunk = doc.chunks[0]region = chunk.regionT0 = chunk.transform.matrixR0 = region.rotC0 = region.centers0 = region.sizechunk = doc.chunks[1]T = chunk.transform.matrix.inv() * T0 R = PhotoScan.Matrix( [[T[0,0],T[0,1],T[0,2]], [T[1,0],T[1,1],T[1,2]], [T[2,0],T[2,1],T[2,2]]]) scale = R.row(0).norm()R = R * (1/scale) region.rot = R * R0c = T.mulp(C0)region.center = cregion.size = s0 * scale / 1. chunk.region = region`
Best regards,
Alexey Pasumansky,
Agisoft LLC

#### Claude

• Newbie
• Posts: 23
##### Re: Regions Alignment
« Reply #7 on: February 06, 2015, 01:26:23 PM »
I don't know what I doing wring. When I run from file nothing appear in console. When I put in in console and hit enter apear this:

File "<console>", line 1
import PhotoScan

doc = PhotoScan.app.document
chunk = doc.chunks[0]
region = chunk.region

T0 = chunk.transform.matrix

R0 = region.rot
C0 = region.center
s0 = region.size

chunk = doc.chunks[1]

T = chunk.transform.matrix.inv() * T0

R = PhotoScan.Matrix( [[T[0,0],T[0,1],T[0,2]], [T[1,0],T[1,1],T[1,2]], [T[2,0],T[2,1],T[2,2]]])

scale = R.row(0).norm()
R = R * (1/scale)

region.rot = R * R0
c = T.mulp(C0)
region.center = c
region.size = s0 * scale / 1.

chunk.region = region

^
SyntaxError: invalid character in identifier

#### Alexey Pasumansky

• Agisoft Technical Support
• Hero Member
• Posts: 14099
##### Re: Regions Alignment
« Reply #8 on: February 06, 2015, 01:53:28 PM »
Hello Claude,

Please check that there are no additional characters in the first line or unexpected indents.
Best regards,
Alexey Pasumansky,
Agisoft LLC

#### Claude

• Newbie
• Posts: 23
##### Re: Regions Alignment
« Reply #9 on: February 06, 2015, 03:37:29 PM »
I've jut copy your code and save as box.py. Run script and nothing. Next past this code in consol.
I know nothing about coding so for me is like magic.
I need very much this script. What I could do wrong? How I shoud use this script?

Best

#### Alexey Pasumansky

• Agisoft Technical Support
• Hero Member
• Posts: 14099
##### Re: Regions Alignment
« Reply #10 on: February 06, 2015, 03:59:29 PM »
Hello Claude,

Sent you the script via e-mail.
Best regards,
Alexey Pasumansky,
Agisoft LLC

#### igor73

• Full Member
• Posts: 228
##### Re: Regions Alignment
« Reply #11 on: February 06, 2015, 09:38:07 PM »
Would be a great feature for future updates if we could do this without messing with Phyton.

#### Alexey Pasumansky

• Agisoft Technical Support
• Hero Member
• Posts: 14099
##### Re: Regions Alignment
« Reply #12 on: February 09, 2015, 02:39:03 PM »
Have put the script that copies bounding box from the active chunk to all other chunks in the project to our Wiki pages:
http://wiki.agisoft.com/wiki/Python
Best regards,
Alexey Pasumansky,
Agisoft LLC

#### r.yashmi

• Newbie
• Posts: 1
##### Re: Regions Alignment
« Reply #13 on: May 18, 2019, 10:55:09 AM »
Hi,
any chance to have the script codes for Metashape 1.5.2 build 7838 64 bit?
and how to run the code?

Have put the script that copies bounding box from the active chunk to all other chunks in the project to our Wiki pages:
http://wiki.agisoft.com/wiki/Python

#### dysano

• Newbie
• Posts: 5
##### Re: Regions Alignment
« Reply #14 on: September 28, 2022, 03:46:07 PM »
Hello, is this script also valid for metashape 1.7.4?