Skip to content

Commit

Permalink
Add support for Panchro camera serie
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastien Courroux committed Dec 13, 2023
1 parent 236cd23 commit eeaf6e8
Show file tree
Hide file tree
Showing 176 changed files with 218,676 additions and 1,588 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Add any directories, files, or patterns you don't want to be tracked by version control
*.pyc
.ipynb_checkpoints
.vscode
/.idea
__pycache__
/dist/
/*.egg-info
853 changes: 853 additions & 0 deletions Alignment v2.ipynb

Large diffs are not rendered by default.

25 changes: 16 additions & 9 deletions Alignment-10Band.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
"panelNames = None\n",
"paneCap = None\n",
"\n",
"imagePath = os.path.join('.','data','10BANDSET','000')\n",
"imageNames = glob.glob(os.path.join(imagePath,'IMG_0431_*.tif'))\n",
"panelNames = glob.glob(os.path.join(imagePath,'IMG_0000_*.tif'))\n",
"imagePath = os.path.join('.','data','REDEDGE-MX-DUAL')\n",
"imageNames = glob.glob(os.path.join(imagePath,'IMG_0007_*.tif'))\n",
"panelNames = glob.glob(os.path.join(imagePath,'IMG_0001_*.tif'))\n",
"\n",
"# Allow this code to align both radiance and reflectance images; bu excluding\n",
"# a definition for panelNames above, radiance images will be used\n",
Expand Down Expand Up @@ -115,7 +115,7 @@
"warp_mode = cv2.MOTION_HOMOGRAPHY # MOTION_HOMOGRAPHY or MOTION_AFFINE. For Altum images only use HOMOGRAPHY\n",
"pyramid_levels = 3 # for 10-band imagery we use a 3-level pyramid. In some cases\n",
"\n",
"print(\"Alinging images. Depending on settings this can take from a few seconds to many minutes\")\n",
"print(\"Aligning images. Depending on settings this can take from a few seconds to many minutes\")\n",
"# Can potentially increase max_iterations for better results, but longer runtimes\n",
"warp_matrices, alignment_pairs = imageutils.align_capture(capture,\n",
" ref_index = match_index,\n",
Expand All @@ -137,11 +137,18 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"\n",
"cropped_dimensions, edges = imageutils.find_crop_bounds(capture, warp_matrices, warp_mode=warp_mode)\n",
"im_aligned = imageutils.aligned_capture(capture, warp_matrices, warp_mode, cropped_dimensions, match_index, img_type=img_type)"
"im_aligned = imageutils.aligned_capture(capture, warp_matrices, warp_mode, cropped_dimensions, match_index, img_type=img_type)\n",
"display(im_aligned)\n",
"print(\"fff\")\n",
"im_aligned = capture.create_aligned_capture(warp_matrices=warp_matrices, motion_type=warp_mode, img_type=img_type, match_index=match_index)\n",
"display(im_aligned)"
]
},
{
Expand Down Expand Up @@ -269,7 +276,7 @@
"\n",
"sort_by_wavelength = True # set to false if you want stacks in camera-band-index order\n",
" \n",
"outRaster = driver.Create(filename+\".tiff\", cols, rows, bands, gdal.GDT_UInt16, options = [ 'INTERLEAVE=BAND','COMPRESS=DEFLATE' ])\n",
"outRaster = driver.Create(filename+\"C.tiff\", cols, rows, bands, gdal.GDT_UInt16, options = [ 'INTERLEAVE=BAND','COMPRESS=DEFLATE' ])\n",
"try:\n",
" if outRaster is None:\n",
" raise IOError(\"could not load gdal GeoTiff driver\")\n",
Expand Down Expand Up @@ -481,7 +488,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -495,7 +502,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.7.12"
},
"toc": {
"nav_menu": {},
Expand Down
32 changes: 21 additions & 11 deletions Alignment-RigRelatives.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,20 @@
"import os, glob\n",
"import micasense.capture as capture\n",
"%matplotlib inline\n",
"from pathlib import Path\n",
"\n",
"panelNames = None\n",
"\n",
"# This is an altum image with RigRelatives and a thermal band\n",
"imagePath = os.path.join('.','data','ALTUM1SET','000')\n",
"imageNames = glob.glob(os.path.join(imagePath,'IMG_0008_*.tif'))\n",
"panelNames = glob.glob(os.path.join(imagePath,'IMG_0000_*.tif'))\n",
"# This is an Altum image with RigRelatives and a thermal band\n",
"\n",
"imagePath = Path(\"./data/ALTUM\")\n",
"\n",
"# these will return lists of image paths as strings \n",
"imageNames = list(imagePath.glob('IMG_0021_*.tif'))\n",
"imageNames = [x.as_posix() for x in imageNames]\n",
"\n",
"panelNames = list(imagePath.glob('IMG_0000_*.tif'))\n",
"panelNames = [x.as_posix() for x in panelNames]\n",
"\n",
"if panelNames is not None:\n",
" panelCap = capture.Capture.from_filelist(panelNames)\n",
Expand All @@ -61,7 +68,7 @@
" if panelCap.panel_albedo() is not None:\n",
" panel_reflectance_by_band = panelCap.panel_albedo()\n",
" else:\n",
" panel_reflectance_by_band = [0.67, 0.69, 0.68, 0.61, 0.67] #RedEdge band_index order\n",
" panel_reflectance_by_band = [0.49, 0.49, 0.49, 0.49, 0.49] #RedEdge band_index order\n",
" panel_irradiance = panelCap.panel_irradiance(panel_reflectance_by_band) \n",
" img_type = \"reflectance\"\n",
" capture.plot_undistorted_reflectance(panel_irradiance)\n",
Expand Down Expand Up @@ -97,11 +104,14 @@
"import micasense.imageutils as imageutils\n",
"import micasense.plotutils as plotutils\n",
"\n",
"reference_band = 5\n",
"warp_mode = cv2.MOTION_HOMOGRAPHY\n",
"warp_matrices = capture.get_warp_matrices()\n",
"warp_matrices = capture.get_warp_matrices(ref_index=reference_band)\n",
"\n",
"cropped_dimensions,edges = imageutils.find_crop_bounds(capture,warp_matrices,reference_band=reference_band)\n",
"im_aligned = imageutils.aligned_capture(capture, warp_matrices, warp_mode, cropped_dimensions, reference_band, img_type=img_type)\n",
"\n",
"cropped_dimensions,edges = imageutils.find_crop_bounds(capture,warp_matrices)\n",
"im_aligned = imageutils.aligned_capture(capture, warp_matrices, warp_mode, cropped_dimensions, None, img_type=img_type)\n",
"print(im_aligned.shape)\n",
"\n",
"print(\"warp_matrices={}\".format(warp_matrices))"
]
Expand All @@ -128,7 +138,7 @@
"cir_band_indices = [3,2,1]\n",
"\n",
"# Create an empty normalized stack for viewing\n",
"im_display = np.zeros((im_aligned.shape[0],im_aligned.shape[1],capture.num_bands+1), dtype=np.float32 )\n",
"im_display = np.zeros((im_aligned.shape[0],im_aligned.shape[1],im_aligned.shape[2]), dtype=np.float32 )\n",
"\n",
"im_min = np.percentile(im_aligned[:,:,0:2].flatten(), 0.1) # modify with these percentilse to adjust contrast\n",
"im_max = np.percentile(im_aligned[:,:,0:2].flatten(), 99.9) # for many images, 0.5 and 99.5 are good values\n",
Expand Down Expand Up @@ -451,7 +461,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -465,7 +475,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.7.12"
},
"toc": {
"nav_menu": {},
Expand Down
39 changes: 19 additions & 20 deletions Alignment.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,28 @@
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"scrolled": false
},
"outputs": [],
"source": [
"import os, glob\n",
"import micasense.capture as capture\n",
"%matplotlib inline\n",
"from pathlib import Path\n",
"import matplotlib.pyplot as plt\n",
"plt.rcParams[\"figure.facecolor\"] = \"w\"\n",
"\n",
"panelNames = None\n",
"\n",
"# # This is an older RedEdge image without RigRelatives\n",
"# imagePath = os.path.join(os.path.abspath('.'),'data','0000SET','000')\n",
"# imageNames = glob.glob(os.path.join(imagePath,'IMG_0001_*.tif'))\n",
"# panelNames = glob.glob(os.path.join(imagePath,'IMG_0000_*.tif'))\n",
"\n",
"# # Image from the example RedEdge imageSet (see the ImageSet notebook) without RigRelatives.\n",
"# imagePath = os.path.expanduser(os.path.join('~','Downloads','RedEdgeImageSet','0000SET'))\n",
"# imageNames = glob.glob(os.path.join(imagePath,'000','IMG_0013_*.tif'))\n",
"# panelNames = glob.glob(os.path.join(imagePath,'000','IMG_0000_*.tif'))\n",
"imagePath = Path(\"./data/ALTUM\")\n",
"\n",
"# This is an altum image with RigRelatives and a thermal band\n",
"imagePath = os.path.join('.','data','ALTUM1SET','000')\n",
"imageNames = glob.glob(os.path.join(imagePath,'IMG_0245_*.tif'))\n",
"panelNames = glob.glob(os.path.join(imagePath,'IMG_0000_*.tif'))\n",
"# these will return lists of image paths as strings \n",
"imageNames = list(imagePath.glob('IMG_0021_*.tif'))\n",
"imageNames = [x.as_posix() for x in imageNames]\n",
"\n",
"panelNames = list(imagePath.glob('IMG_0000_*.tif'))\n",
"panelNames = [x.as_posix() for x in panelNames]\n",
"\n",
"# Allow this code to align both radiance and reflectance images; bu excluding\n",
"# a definition for panelNames above, radiance images will be used\n",
Expand All @@ -76,7 +74,7 @@
" if panelCap.panel_albedo() is not None:\n",
" panel_reflectance_by_band = panelCap.panel_albedo()\n",
" else:\n",
" panel_reflectance_by_band = [0.67, 0.69, 0.68, 0.61, 0.67] #RedEdge band_index order\n",
" panel_reflectance_by_band = [0.49, 0.49, 0.49, 0.49, 0.49] #RedEdge band_index order\n",
" panel_irradiance = panelCap.panel_irradiance(panel_reflectance_by_band) \n",
" img_type = \"reflectance\"\n",
" capture.plot_undistorted_reflectance(panel_irradiance)\n",
Expand Down Expand Up @@ -130,7 +128,7 @@
"warp_mode = cv2.MOTION_HOMOGRAPHY # MOTION_HOMOGRAPHY or MOTION_AFFINE. For Altum images only use HOMOGRAPHY\n",
"pyramid_levels = 0 # for images with RigRelatives, setting this to 0 or 1 may improve alignment\n",
"\n",
"print(\"Alinging images. Depending on settings this can take from a few seconds to many minutes\")\n",
"print(\"Aligning images. Depending on settings this can take from a few seconds to many minutes\")\n",
"# Can potentially increase max_iterations for better results, but longer runtimes\n",
"warp_matrices, alignment_pairs = imageutils.align_capture(capture,\n",
" ref_index = match_index,\n",
Expand All @@ -155,7 +153,8 @@
"metadata": {},
"outputs": [],
"source": [
"cropped_dimensions, edges = imageutils.find_crop_bounds(capture, warp_matrices, warp_mode=warp_mode)\n",
"cropped_dimensions, edges = imageutils.find_crop_bounds(capture, warp_matrices, warp_mode=warp_mode, reference_band=match_index)\n",
"print(cropped_dimensions)\n",
"im_aligned = imageutils.aligned_capture(capture, warp_matrices, warp_mode, cropped_dimensions, match_index, img_type=img_type)"
]
},
Expand Down Expand Up @@ -288,7 +287,7 @@
"\n",
"if im_aligned.shape[2] == 6:\n",
" filename = filename + \"t\" #thermal\n",
"outRaster = driver.Create(filename+\".tiff\", cols, rows, im_aligned.shape[2], gdal.GDT_UInt16)\n",
"outRaster = driver.Create(filename+\"B.tiff\", cols, rows, im_aligned.shape[2], gdal.GDT_UInt16)\n",
"\n",
"normalize = (img_type == 'radiance') # normalize radiance images to fit with in UInt16\n",
"\n",
Expand Down Expand Up @@ -559,7 +558,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -573,7 +572,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.7.12"
},
"toc": {
"nav_menu": {},
Expand Down
Loading

0 comments on commit eeaf6e8

Please sign in to comment.