Skip to content

Commit

Permalink
Merge pull request #43 from SenteraLLC/ssm-4092-m3m-support
Browse files Browse the repository at this point in the history
SSM-4092: Add Support for Mavic 3 Multispectral
  • Loading branch information
SamCWill authored Nov 8, 2023
2 parents d029b26 + c2cab9c commit 8dee06a
Show file tree
Hide file tree
Showing 11 changed files with 382 additions and 337 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/lint-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Lint and Test
on:
push:
branches-ignore:
[master]

jobs:
lint:
name: Lint and test
runs-on: ubuntu-20.04
steps:
- name: Checkout repository
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
with:
fetch-depth: 0

- name: Install Exiftool
run: |
wget https://exiftool.org/Image-ExifTool-12.52.tar.gz
gzip -dc Image-ExifTool-12.52.tar.gz | tar -xf -
cd Image-ExifTool-12.52
perl Makefile.PL
sudo make install
cd ..
- name: Install poetry dependency manager
run: pipx install poetry==1.5.1

- name: Setup Python environment
uses: actions/setup-python@v4.7.1
with:
cache: poetry

- name: Enforce style guides and lint rules
uses: pre-commit/action@646c83fcd040023954eafda54b4db0192ce70507 # v3.0.0

- name: Install dependencies
run: poetry install

- name: Run unit tests
run: poetry run pytest

- name: Confirm repo is clean
run: git diff-index --quiet HEAD
37 changes: 37 additions & 0 deletions .github/workflows/main-branch.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Main branch
on:
push:
branches: master

jobs:
version:
name: Generate a version
runs-on: ubuntu-20.04
steps:
- id: version
name: Generate a date-based version
run: echo "version=$(date +'%Y.%m%d.%H%M%S')" >> "$GITHUB_OUTPUT"
outputs:
version: ${{ steps.version.outputs.version }}

release:
name: Create a GitHub Release
needs: [version]
runs-on: ubuntu-20.04
permissions:
contents: write
steps:
- name: Create a GitHub Release
uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1
with:
result-encoding: string
retries: 3
script: |
github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: "${{needs.version.outputs.version}}",
target_commitish: context.sha,
name: "${{needs.version.outputs.version}}",
generate_release_notes: true
})
17 changes: 0 additions & 17 deletions .travis.yml

This file was deleted.

2 changes: 0 additions & 2 deletions cfg/exiftool.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@
GPSXYAccuracy => { Writable => 'real' },
GPSZAccuracy => { Writable => 'real' },
FlightUUID => { },
CentralWaveLength => { },
BandName => { List => 'Seq' },
RigName => { },
RigCameraIndex => { Writable => 'integer' },
BandName => { List => 'Seq' },
Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ dependencies:
# subpackage dependencies
# Sentera dependencies
- pip:
- git+https://github.com/SenteraLLC/py-image-metadata-parser.git@v1.14.1
- git+https://github.com/SenteraLLC/py-image-metadata-parser.git@v1.15.2
2 changes: 1 addition & 1 deletion imgcorrect/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.7.1"
__version__ = "1.7.2"
13 changes: 6 additions & 7 deletions imgcorrect/detect_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
from PIL import Image

# Constants
MAX_VAL_12BIT = 4096

ARUCO_SIDE_LENGTH_M = 0.07
ARUCO_TOP_TO_PANEL_CENTER_M = 0.06

Expand All @@ -33,14 +31,16 @@ def bounds(self):
)


def convert_12bit_to_type(image, desired_type=np.uint8):
def convert_to_type(image, max_val, desired_type=np.uint8):
"""
Convert the 12-bit tiff from a 6X sensor to a numpy compatible form.
Convert the data type of a numpy array to another data type, scaling accordingly.
:param image: The array to convert
:param max_val: The max_val of the input array
:param desired_type: The desired type
:return: The converted image in numpy.array format
"""
image = image / MAX_VAL_12BIT # Scale to 0-1
image = image / max_val # Scale to 0-1
image = np.iinfo(desired_type).max * image # Scale back to desired type
return image.astype(desired_type)

Expand Down Expand Up @@ -132,10 +132,9 @@ def get_reflectance(row):
:return: The average value of the reflectance panel a valid calibration image, NaN if image is invalid
"""
if "band_math" not in row.index:
# Read the original (12-bit) tiff with the next largest commonly used container (16-bit)
image = np.asarray(Image.open(row["image_path"])).astype(np.uint16)
# OpenCV aruco detection only accepts 8-bit data
panel = extract_panel_bounds(convert_12bit_to_type(image, np.uint8))
panel = extract_panel_bounds(convert_to_type(image, row.max_val, np.uint8))
else:
image = np.asarray(Image.open(row["image_path"])).astype(np.uint8)
panel = extract_panel_bounds(image)
Expand Down
9 changes: 6 additions & 3 deletions imgcorrect/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def apply_sensor_settings(image_df):
"""Rebuild image dataframe with settings based on sensor model."""
rows = []

for index, row in image_df.iterrows():
for _, row in image_df.iterrows():
for s in sensor_defs:
# verify image metadata matches that of a supported sensor
meets_criteria = True
Expand Down Expand Up @@ -82,8 +82,11 @@ def create_image_df(input_path, output_path):

image_df = pd.DataFrame()

image_df["image_path"] = glob(input_path + "/**/*.tif", recursive=True) + glob(
input_path + "/**/*.jpg", recursive=True
image_df["image_path"] = (
glob(input_path + "/**/*.tif", recursive=True)
+ glob(input_path + "/**/*.jpg", recursive=True)
+ glob(input_path + "/**/*.TIF", recursive=True)
+ glob(input_path + "/**/*.JPG", recursive=True)
)
image_df["image_root"] = image_df.image_path.apply(os.path.dirname)
image_df["output_path"] = image_df.image_path.str.replace(
Expand Down
16 changes: 16 additions & 0 deletions imgcorrect/sensor_defs.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
"sensor": "6x",
"cal_in_path": True,
"independent_ils": True,
"max_val": 4096,
},
},
{
Expand All @@ -113,6 +114,21 @@
"sensor": "6x_thermal",
"cal_in_path": True,
"independent_ils": True,
"max_val": 4096,
},
},
{
"criteria": {"Image Make": "DJI", "Image Model": "M3M"},
"ignore_criteria": {
"EXIF ColorSpace": [
"sRGB", # RGB
]
},
"settings": {
"sensor": "M3M",
"cal_in_path": False,
"independent_ils": True,
"max_val": 65536,
},
},
]
Loading

0 comments on commit 8dee06a

Please sign in to comment.