Skip to content

Commit

Permalink
Merge pull request #60 from Addalin/adi
Browse files Browse the repository at this point in the history
Adi
  • Loading branch information
Addalin committed Jan 2, 2020
2 parents 827bc4d + 2583c47 commit d9b12d1
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 49 deletions.
72 changes: 36 additions & 36 deletions CameraNetwork/export.py
@@ -1,38 +1,38 @@
##
## Copyright (C) 2017, Amit Aides, all rights reserved.
##
## This file is part of Camera Network
## (see https://bitbucket.org/amitibo/cameranetwork_git).
##
## Redistribution and use in source and binary forms, with or without modification,
## are permitted provided that the following conditions are met:
##
## 1) The software is provided under the terms of this license strictly for
## academic, non-commercial, not-for-profit purposes.
## 2) Redistributions of source code must retain the above copyright notice, this
## list of conditions (license) and the following disclaimer.
## 3) Redistributions in binary form must reproduce the above copyright notice,
## this list of conditions (license) and the following disclaimer in the
## documentation and/or other materials provided with the distribution.
## 4) The name of the author may not be used to endorse or promote products derived
## from this software without specific prior written permission.
## 5) As this software depends on other libraries, the user must adhere to and keep
## in place any licensing terms of those libraries.
## 6) Any publications arising from the use of this software, including but not
## limited to academic journal and conference publications, technical reports and
## manuals, must cite the following works:
## Dmitry Veikherman, Amit Aides, Yoav Y. Schechner and Aviad Levis, "Clouds in The Cloud" Proc. ACCV, pp. 659-674 (2014).
##
## THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
## EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
## INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
## BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
## LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
## OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
## ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.##
##
## Copyright (C) 2017, Amit Aides, all rights reserved.
##
## This file is part of Camera Network
## (see https://bitbucket.org/amitibo/cameranetwork_git).
##
## Redistribution and use in source and binary forms, with or without modification,
## are permitted provided that the following conditions are met:
##
## 1) The software is provided under the terms of this license strictly for
## academic, non-commercial, not-for-profit purposes.
## 2) Redistributions of source code must retain the above copyright notice, this
## list of conditions (license) and the following disclaimer.
## 3) Redistributions in binary form must reproduce the above copyright notice,
## this list of conditions (license) and the following disclaimer in the
## documentation and/or other materials provided with the distribution.
## 4) The name of the author may not be used to endorse or promote products derived
## from this software without specific prior written permission.
## 5) As this software depends on other libraries, the user must adhere to and keep
## in place any licensing terms of those libraries.
## 6) Any publications arising from the use of this software, including but not
## limited to academic journal and conference publications, technical reports and
## manuals, must cite the following works:
## Dmitry Veikherman, Amit Aides, Yoav Y. Schechner and Aviad Levis, "Clouds in The Cloud" Proc. ACCV, pp. 659-674 (2014).
##
## THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED
## WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
## MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
## EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
## INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
## BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
## LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
## OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
## ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.##
"""Utilites for handling export to solver.
"""
from __future__ import division
Expand Down Expand Up @@ -63,7 +63,7 @@ def exportToShdom(
base_path (str): Path to store export data.
array_items (list): List of array items.
grid (list): List of grid array. This is the grid to reconstruct.
lat, lon, lat (float): The latitude, longitude and altitude of the center
lat, lon, alt (float): The latitude, longitude and altitude of the center
of the grid.
progress_callback (function): Callback function to update the (GUI) with
the progress of the export.
Expand Down
2 changes: 1 addition & 1 deletion CameraNetwork/global_settings.py
Expand Up @@ -264,7 +264,7 @@
#
# Amit:
# The default radiometric settings were taken from camera 109.
#
# TODO: what are the units?
DEFAULT_RADIOMETRIC_SETTINGS = \
[0.077523644728250449, 0.11163146919636868, 0.11847859109577621]

Expand Down
17 changes: 10 additions & 7 deletions CameraNetwork/gui/main.py
Expand Up @@ -883,7 +883,7 @@ def projectECEF(self, ECEF_pts, filter_fov=True, errstate='warn'):
Args:
ECEF_pts (tuple of arrays): points in ECEF coords.
fiter_fov (bool, optional): If True, points below the horizion
filter_fov (bool, optional): If True, points below the horizion
will not be returned. If false, the indices of these points
will be returned.
Expand Down Expand Up @@ -938,17 +938,20 @@ def _update_cloud_weights(self, change):
if change["value"] is None:
return

# The following calculation is based on page 23 in Amit's thesis (Computation of cloud scores maps)
# TODO: consider to change cloud score in 2D .
r = self.img_array[..., 0].astype(np.float)
b = self.img_array[..., 2].astype(np.float)

cloud_weights = np.zeros_like(r)
eps = np.finfo(b.dtype).eps

threshold = self.cloud_weight_threshold
threshold = self.cloud_weight_threshold # currently 0.8
ratio = r / (b+eps)
ratio_mask = ratio>threshold
cloud_weights[ratio_mask] = \
(2-threshold)/(1-threshold)*(ratio[ratio_mask]-threshold)/(ratio[ratio_mask]+1-threshold)
#The current calculation: ( 1.2 / 0.2 ) * (r - 0.8 ) / (r + 0.2 )

#
# Limit cloud_weights to 1.
Expand Down Expand Up @@ -1403,15 +1406,15 @@ class MainModel(Atom):
#
# Reconstruction Grid parameters.
# Note:
# There are two grids used:
# There are three grids used:
# - GRID_VIS_ECEF: Used for visualization on the camera array.
# - GRID_ECEF: Used for the visual hull algorithm.
# - GRID_NED: The grid exported for reconstruction.
#
delx = Float(150)
dely = Float(150)
delz = Float(100)
TOG = Float(12000)
delx = Float(150) # [meters]
dely = Float(150) # [meters]
delz = Float(100) # [meters]
TOG = Float(12000) # [meters]
GRID_VIS_ECEF = Tuple()
GRID_ECEF = Tuple()
GRID_NED = Tuple()
Expand Down
14 changes: 9 additions & 5 deletions CameraNetwork/image_utils.py
Expand Up @@ -33,7 +33,8 @@
## LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
## OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
## ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.##
"""General utilities for image processing.
"""
General utilities for image processing.
"""
from __future__ import division, absolute_import, print_function
from CameraNetwork.utils import obj
Expand Down Expand Up @@ -701,23 +702,26 @@ def calc_visual_hull(
# Calculate the collective clouds weight.
#
weights = np.array(grid_scores).prod(axis=0)

# TODO: Consider to change the prod to other arithmethic calculation. (maybe OR ?) (I think this removes clouds edges from the space carving)
#
# voxels that are not seen (outside the fov/sun_mask) by at least two cameras
# are zeroed.
#
grid_masks = np.array(grid_masks).sum(axis=0)
weights[grid_masks<2] = 0

#
# More cameras viewing the voxel increase it's own score.
#
nzi = weights > 0
weights[nzi] = weights[nzi]**(1/grid_masks[nzi])

#
# Calculate color consistency as described in the article
# Calculate color consistency as described in the article. (see Equation 5.5 in p.54 , Amit's thesis)
#
std_rgb = np.dstack(cloud_rgb).std(axis=2).mean(axis=1)
mean_rgb = np.dstack(cloud_rgb).mean(axis=2).mean(axis=1)
color_consistency = np.exp(-(std_rgb/mean_rgb)/color_consistency_sigma)

color_consistency = np.exp(-(std_rgb/(mean_rgb + np.finfo(float).eps))/color_consistency_sigma)
#
# Take into account both the clouds weights and photo consistency.
#
Expand Down
26 changes: 26 additions & 0 deletions Image_pipeline.md
Expand Up @@ -138,7 +138,33 @@ For example:
2. What inputs/changes are required for a new experiment?

###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 is version used as the common 3D grid that is being used for moving the view-of-point arround the grid conveniently according to cameras positions.
2. The NED (X,Y,Z) 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).
The 3D NED grid is of size 12 X 12 X 10 [km^3], having 81 X 81 X 121 voxels, each voxel size is of 150 X 150 X 100 [m^3].
The grid is projected to a 2d grid, shown as red dots on image plane).
This is done when choosing: `View settings`-->`Widgets`--> `show grid`.
// TODO : add snapshots of the 3d view and image with red dotted grid.
This method is also being used when computing the [space carve](https://github.com/Addalin/cameranetwork/blob/fa7d2b2f29d5217cdc2b216ae55d147393e9db0d/CameraNetwork/image_utils.py#L738-L810) score per each view.
This is done when choosing in the map view `Space carving`-->`Show space carving`.
// TODO : add snapshots of the map with the space carving.
Another usage of this method is when applying [Update LOS](https://github.com/Addalin/cameranetwork/blob/c69dda2adc041dc2dc98660b34e57769213f23a9/CameraNetwork/gui/main.py#L620-L667). Ths function converts the also uses
LOS of a single image to the epipolar lines on all other images.
// TODO : add snapshot of this optsion and how to get to it.

2. [Space carving](https://github.com/Addalin/cameranetwork/blob/c69dda2adc041dc2dc98660b34e57769213f23a9/CameraNetwork/gui/main.py#L317-L337) - for the grid. (// TODOL add snapshot and explantaion here.). Calls for space carve on each view separatly using proccess pool.

[Space carving](https://github.com/Addalin/cameranetwork/blob/fa7d2b2f29d5217cdc2b216ae55d147393e9db0d/CameraNetwork/image_utils.py#L739-L810) - for each view, projecting the the 3d grid onto the image plane.
This process is done according to the no. of pertubations chosen by the user (// TODOL add snapshot and explantaion here.). At the end receiving mean of scores for the voxels that are seen from this view (a.k.a `grid_score`). The grid score is based on cloud score that is done on the 2D image.
[The cloud scoring](https://github.com/Addalin/cameranetwork/blob/c69dda2adc041dc2dc98660b34e57769213f23a9/CameraNetwork/gui/main.py#L936-L987) in the image plane is based on page 23 in Amit's thesis (Computation of cloud scores maps) ( cloud sore is caled `cloud_weights`)

Then the grid level method, collects scores from all servers.

### TODO: Other issues to cover regarding image pipeline:
1. Space curving - the transition from 2d and 3d.
Expand Down

0 comments on commit d9b12d1

Please sign in to comment.