Skip to content

Commit

Permalink
Add the flatfield constant and remove the hard coding of the names, w…
Browse files Browse the repository at this point in the history
…hilst this is not used today it will be
  • Loading branch information
davisadam10 committed Jun 12, 2024
1 parent f692f5f commit 9174f3e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 20 deletions.
18 changes: 10 additions & 8 deletions aces/idt/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,11 @@ def _update_data_from_file_structure(self, root_directory: Path):
EV
] = list((colour_checker_directory / exposure_directory).glob("*.*"))

# TODO Is flatfield used? ive only ever scene colour checker and grey_card used
flatfield_directory = root_directory / DirectoryStructure.DATA / "flatfield"
flatfield_directory = (
root_directory / DirectoryStructure.DATA / DirectoryStructure.FLATFIELD
)
if flatfield_directory.exists():
self.project_settings.data["flatfield"] = list(
self.project_settings.data[DirectoryStructure.FLATFIELD] = list(
flatfield_directory.glob("*.*")
)
grey_card_directory = (
Expand Down Expand Up @@ -197,18 +198,19 @@ def _update_data_with_posix_paths(self, root_directory: Path):
float(exposure)
] = images

# TODO Is flatfield used? ive only ever scene colour checker and grey_card used
if self.project_settings.data.get("flatfield", []):
if self.project_settings.data.get(DirectoryStructure.FLATFIELD, []):
images = [
Path(root_directory) / image
for image in self.project_settings.data.get("flatfield", [])
for image in self.project_settings.data.get(
DirectoryStructure.FLATFIELD, []
)
]
for image in images:
attest(image.exists())

self.project_settings.data["flatfield"] = images
self.project_settings.data[DirectoryStructure.FLATFIELD] = images
else:
self.project_settings.data["flatfield"] = []
self.project_settings.data[DirectoryStructure.FLATFIELD] = []

if self.project_settings.data.get(DirectoryStructure.GREY_CARD, []):
images = [
Expand Down
1 change: 1 addition & 0 deletions aces/idt/core/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class DirectoryStructure:
DATA: ClassVar[str] = "data"
COLOUR_CHECKER: ClassVar[str] = "colour_checker"
GREY_CARD: ClassVar[str] = "grey_card"
FLATFIELD: ClassVar[str] = "flatfield"


class UITypes:
Expand Down
31 changes: 19 additions & 12 deletions aces/idt/generators/base_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,11 +328,14 @@ def _reformat_image(image):
# Disabling orientation as we now have an oriented quadrilateral
settings.reference_values = None

# TODO Again are we using this?
# Flatfield
if self.project_settings.data.get("flatfield"):
self._samples_analysis["flatfield"] = {"samples_sequence": []}
for path in self.project_settings.data.get("flatfield", []):
if self.project_settings.data.get(DirectoryStructure.FLATFIELD):
self._samples_analysis[DirectoryStructure.FLATFIELD] = {
"samples_sequence": []
}
for path in self.project_settings.data.get(
DirectoryStructure.FLATFIELD, []
):
with working_directory(self.working_directory):
LOGGER.info('Reading flatfield image from "%s"...', path)
image = _reformat_image(read_image(path))
Expand All @@ -345,24 +348,28 @@ def _reformat_image(image):
**settings,
)

self._samples_analysis["flatfield"]["samples_sequence"].append(
data_detection_flatfield.swatch_colours.tolist()
)
self._samples_analysis[DirectoryStructure.FLATFIELD][
"samples_sequence"
].append(data_detection_flatfield.swatch_colours.tolist())

samples_sequence = as_float_array(
[
samples[0]
for samples in self._samples_analysis["flatfield"][
for samples in self._samples_analysis[DirectoryStructure.FLATFIELD][
"samples_sequence"
]
]
)
mask = np.all(~mask_outliers(samples_sequence), axis=-1)

self._samples_analysis["flatfield"]["samples_median"] = np.median(
as_float_array(self._samples_analysis["flatfield"]["samples_sequence"])[
mask
],
self._samples_analysis[DirectoryStructure.FLATFIELD][
"samples_median"
] = np.median(
as_float_array(
self._samples_analysis[DirectoryStructure.FLATFIELD][
"samples_sequence"
]
)[mask],
(0, 1),
).tolist()

Expand Down

0 comments on commit 9174f3e

Please sign in to comment.