Skip to content

Commit

Permalink
Merge pull request #73 from Addalin/adi
Browse files Browse the repository at this point in the history
Adi - update export
update image pipeline
  • Loading branch information
OmerShubi committed Dec 28, 2020
2 parents 09e9be7 + a074772 commit 52e915f
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 8 deletions.
23 changes: 19 additions & 4 deletions CameraNetwork/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"""
from __future__ import division
from CameraNetwork.utils import sun_direction
from CameraNetwork.image_utils import calcSunMaskRect
import cPickle
import cv2
from enaml.application import deferred_call, is_main_thread
Expand Down Expand Up @@ -126,6 +127,14 @@ def exportToShdom(
manual_mask = array_view.image_widget.mask
joint_mask = (manual_mask * array_model.sunshader_mask).astype(np.uint8)

# calculate rectangle around sun mask
rect_sun_mask = calcSunMaskRect (
array_model.img_array.shape ,
sun_alt ,
sun_az ,
radius = array_model.sun_mask_radius
)

#
# Project the grid on the image and check viewed voxels.
# Note:
Expand All @@ -145,16 +154,22 @@ def exportToShdom(
)
continue


export_data[server_id] = dict(
extra_data=extra_data,
R=array_view.image_widget.getArrayRegion(img_array[..., 0]),
G=array_view.image_widget.getArrayRegion(img_array[..., 1]),
B=array_view.image_widget.getArrayRegion(img_array[..., 2]),
PHI=PHI_shdom,
PSI=PSI_shdom,
MASK=array_view.image_widget.getArrayRegion(joint_mask),
SUN_MASK=array_view.image_widget.getArrayRegion(array_model.sun_mask),
Visibility=visibility,
MASK = array_view.image_widget.getArrayRegion(joint_mask),
SUN_MASK = array_view.image_widget.getArrayRegion(array_model.sun_mask),
Visibility = visibility,
manual_mask = array_view.image_widget.getArrayRegion(manual_mask),
cloud_mask = array_view.image_widget.getArrayRegion(array_model.cloud_weights),
sunshader_mask = array_view.image_widget.getArrayRegion(array_model.sunshader_mask),
rect_sun_mask = array_view.image_widget.getArrayRegion(rect_sun_mask)
# TODO: check why getArrayRegion() fails when sending returnMappedCoords=True
)

deferred_call(progress_callback, i / progress_cnt)
Expand Down Expand Up @@ -263,8 +278,8 @@ def calcROIbounds(array_model, array_view):
#
# Get the transform from the ROI to the data.
#
_, tr = roi.getArraySlice(array_model.img_array, array_view.image_widget.img_item)

#~, tr = roi.getArraySlice(array_model.img_array, array_view.image_widget.img_item)
#
# Calculate the bounds.
#
Expand Down
22 changes: 22 additions & 0 deletions CameraNetwork/image_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,12 +583,34 @@ def projectECEFThread(
#
deferred_call(setattr, array_model, 'grid_2D', grid_2D)

def rectangle(center_x, center_y, width_x=0.25, width_y=0.25):
"""Returns a gaussian function with the given parameters"""
return lambda x,y : ((np.abs ( center_x - x ) <= width_x) &
(np.abs ( center_y - y ) <= width_y)).astype(np.int)



def gaussian(center_x, center_y, height=1., width_x=0.25, width_y=0.25):
"""Returns a gaussian function with the given parameters"""

return lambda x, y: height*np.exp(-(((center_x-x)/width_x)**2+((center_y-y)/width_y)**2)/2)

def calcSunMaskRect(img_shape, sun_alt, sun_az, radius=0.25):
"""Calculate a rectangle of the mask for the sun.
The sun pixels are weighted by a gaussian.
"""

sun_r = (np.pi / 2 - sun_alt) / (np.pi / 2)
sun_x = sun_r * np.sin ( sun_az )
sun_y = sun_r * np.cos ( sun_az )

X , Y = np.meshgrid (
np.linspace ( -1 , 1 , img_shape [ 1 ] ) ,
np.linspace ( -1 , 1 , img_shape [ 0 ] )
)

return rectangle(center_x = sun_x,center_y = sun_y,width_x = radius,width_y = radius)(X,Y)

def calcSunMask(img_shape, sun_alt, sun_az, radius=0.25):
"""Calculate a mask for the sun.
Expand Down
14 changes: 11 additions & 3 deletions Image_pipeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ To get the sunphotometer measurements:

For example:

[Radiometric](docs/source/images/radiometric_calibration.png)

![Radiometric](docs/source/images/radiometric_calibration.png)

##### Questions regarding radiometric calibration:
1. What are the final conversion units?
Expand All @@ -146,13 +145,22 @@ For example:
### 4. 3D grid and space curving:
The [geographic coordinate systems](https://en.wikipedia.org/wiki/Geographic_coordinate_system) that are used here are:
1. The ECEF (earth-centered, earth-fixed frame) is the common 3D grid that is being used for moving the point-of-view (the observing camera) around the grid conveniently according to cameras' location (Latitude (\phi), longitude (\lambda),X_ecef,Y_ecef,Z_ecef).
2. The NED (North East Down) grid (X,Y,Z) is used for visualization and reconstruction grid.

![ECEF](docs/source/images/ECEF.png)

2. Local tangent plane coordinates (LTP). The NEU (North East Up) uses grid (X,Y,Z) as follows:
![ECEF2ENU](docs/source/images/ECEF2ENU.png)

See their definitions in the project [here](https://github.com/Addalin/cameranetwork/blob/c69dda2adc041dc2dc98660b34e57769213f23a9/CameraNetwork/gui/main.py#L1393-L1420).
image of the relation between both coordinates systems:

![ECEF_ENU](docs/source/images/ECEF_ENU_Longitude_Latitude_relationships.png)

In *cameranetwork*, the NED (North East Down) grid (X,Y,-Z) convention, is used for visualization and reconstruction grid.


See their definitions in the project [here](https://github.com/Addalin/cameranetwork/blob/c69dda2adc041dc2dc98660b34e57769213f23a9/CameraNetwork/gui/main.py#L1393-L1420).

There are several conversion processes that are being done:

1. [ProjectGrid()](https://github.com/Addalin/cameranetwork/blob/fa7d2b2f29d5217cdc2b216ae55d147393e9db0d/CameraNetwork/image_utils.py#L615-L645) - Projecting the 3D grid of the interest volume, onto image plane. Which uses ecef2ned in [projectECEF()](https://github.com/Addalin/cameranetwork/blob/c69dda2adc041dc2dc98660b34e57769213f23a9/CameraNetwork/gui/main.py#L881-L933).
Expand Down
Binary file added docs/source/images/ECEF.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/images/ECEF2ENU.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion scripts_client/Sessions/Default%20Settings
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ SCPAutoPwd\0\
ACSinUTF\0\
Comment\\
CtrlTabSwitch\0\
Password\bv03p\
Password\v22n3\
ForegroundOnBell\0\
SaveWindowPos\0\
WindowState\0\
Expand Down

0 comments on commit 52e915f

Please sign in to comment.