Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

82 spot analysis for peak intensity correction #87

Merged
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
7f7cedc
add collaborative_dir setting, fix SpotAnalysis __name__ == "__main__…
bbean23 Apr 14, 2024
7f1e53b
start #82 spot analysis for peak intensity correction
bbean23 Apr 15, 2024
11641f9
add CroppingImageProcessor
bbean23 Apr 15, 2024
89a71e3
fix error with ImageAttributeParser subclass __init__ initialization
bbean23 Apr 17, 2024
cce3f96
add method to retrieve a logger function based on the log level
bbean23 Apr 17, 2024
5f5a10c
formatting
bbean23 Apr 17, 2024
5fd2559
add ExposureDetectionImageProcessor, add image_processor_notes to Spo…
bbean23 Apr 17, 2024
56f5498
add TestExposureDetectionImageProcessor
bbean23 Apr 17, 2024
d8fe94b
add AbstractAggregateImageProcessor and associated test
bbean23 Apr 17, 2024
4c14072
add AverageByGroupImageProcessor and associated unit test, fix Cachea…
bbean23 Apr 18, 2024
97d55eb
add write_json and read_json to file_tools.py
bbean23 Apr 19, 2024
04ba15d
more prototyping of the PeakFlux workflow
bbean23 Apr 19, 2024
4237aa4
fix AbstractAggregateImageProcessor and AverageByGroupImageProcessor,…
bbean23 Apr 19, 2024
a5ee42b
fix SpotAnalysisImageAttributeParser by fixing ImageAttributeParser
bbean23 Apr 19, 2024
4a5841f
more debugging options
bbean23 Apr 19, 2024
60093db
add SupportingImagesCollectorImageProcessor, other small code and for…
bbean23 Apr 19, 2024
ad46e21
add NullImageSubtractionImageProcessor.py
bbean23 Apr 19, 2024
de9f978
better comments in CacheableImage
bbean23 Apr 19, 2024
5b0c73d
add ConvolutionImageProcessor
bbean23 Apr 22, 2024
5c011b7
update AbstractFiducial->AbstractFiducials to indicate the plural nat…
bbean23 Apr 24, 2024
f7ac1fa
fix SpotAnalysisOperable
bbean23 Apr 24, 2024
eb141e5
add AnnotationImageProcessor, add PointFiducials
bbean23 Apr 24, 2024
2b7ad94
remove unused imports, fix test file location
bbean23 Apr 24, 2024
bd484e3
add BcsFiducial, BcsLocatorImageProcessor, RenderControlBcs
bbean23 Apr 24, 2024
da10f68
remove unused code from PeakFlux and CroppingImageProcessor
bbean23 Apr 24, 2024
66631a9
add addition comments
bbean23 Apr 24, 2024
0a7a5e5
updating docstrings as suggested in PR
bbean23 Apr 26, 2024
920663b
better comments and code order for SupportingImagesCollectorImageProc…
bbean23 Apr 26, 2024
a6d74a5
add descriptions for the various ImageTypes
bbean23 Apr 26, 2024
c75a80b
better AbstractFiducial.orientation description
bbean23 Apr 26, 2024
c80b85b
formatting
bbean23 Apr 26, 2024
918a09b
better method names and descriptions, to match the comments on PR #87
bbean23 May 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add AnnotationImageProcessor, add PointFiducials
bbean23 committed May 29, 2024
commit eb141e5f7a0e3ebd58fbbc923369d88cf4b93f37
4 changes: 2 additions & 2 deletions opencsp/common/lib/cv/AbstractFiducials.py
Original file line number Diff line number Diff line change
@@ -17,8 +17,8 @@ class AbstractFiducials(ABC):
def __init__(self, style=None, pixels_to_meters: Callable[[p2.Pxy], v3.Vxyz] = None):
"""
A collection of markers (such as an ArUco board) that is used to orient the camera relative to observed objects
in the scene. It is suggested that each implementing class be paired with a complementary FiducialLocator or
PredictingFiducialLocator class.
in the scene. It is suggested that each implementing class be paired with a complementary locator method or
SpotAnalysisImageProcessor.

Parameters
----------
38 changes: 38 additions & 0 deletions opencsp/common/lib/cv/fiducials/PointFiducials.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import numpy as np

from opencsp.common.lib.cv.AbstractFiducials import AbstractFiducials
import opencsp.common.lib.geometry.Vxyz as v3
import opencsp.common.lib.geometry.Pxy as p2
import opencsp.common.lib.geometry.RegionXY as reg


class PointFiducials(AbstractFiducials):
def __init__(self, style=None, points: p2.Pxy = None):
"""
A collection of pixel locations where points of interest are located in an image.
"""
super().__init__(style)
self.points = points

def get_bounding_box(self, index=0) -> reg.RegionXY:
# TODO untested
return reg.RegionXY.from_vertices(p2.Pxy((self.points.x[index], self.points.y[index])))

@property
def origin(self) -> p2.Pxy:
return self.points

@property
def orientation(self) -> v3.Vxyz:
# TODO untested
return np.zeros((3, self.points.x.size))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can also do len(self.points) fyi. Not that this needs to be changed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do like that more. Done!


@property
def size(self) -> list[float]:
# TODO untested
return [0] * len(self.points)

@property
def scale(self) -> list[float]:
# TODO untested
return [0] * len(self.points)
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import dataclasses
from typing import Callable

import matplotlib.pyplot as plt
import numpy as np

from opencsp.common.lib.cv.AbstractFiducials import AbstractFiducials
from opencsp.common.lib.cv.CacheableImage import CacheableImage
from opencsp.common.lib.cv.fiducials.PointFiducials import PointFiducials
from opencsp.common.lib.cv.spot_analysis.SpotAnalysisOperable import SpotAnalysisOperable
from opencsp.common.lib.cv.spot_analysis.image_processor.AbstractSpotAnalysisImageProcessor import (
AbstractSpotAnalysisImagesProcessor,
)
import opencsp.common.lib.geometry.Pxy as p2
import opencsp.common.lib.opencsp_path.opencsp_root_path as orp
import opencsp.common.lib.render.figure_management as fm
import opencsp.common.lib.render_control.RenderControlPointSeq as rcps
import opencsp.common.lib.tool.file_tools as ft
import opencsp.common.lib.tool.log_tools as lt


class AnnotationImageProcessor(AbstractSpotAnalysisImagesProcessor):
def __init__(self):
super().__init__(self.__class__.__name__)

def _execute(self, operable: SpotAnalysisOperable, is_last: bool) -> list[SpotAnalysisOperable]:
old_image = operable.primary_image.nparray
new_image = np.array(old_image)

for fiducials in operable.given_fiducials:
new_image = fiducials.render_to_image(new_image)
for fiducials in operable.found_fiducials:
new_image = fiducials.render_to_image(new_image)

cacheable_image = CacheableImage(new_image, source_path=operable.primary_image.source_path)
ret = dataclasses.replace(operable, primary_image=cacheable_image)
return [ret]


if __name__ == "__main__":
import os

indir = ft.norm_path(
os.path.join(
orp.opencsp_scratch_dir(),
"solar_noon/dev/2023-05-12_SpringEquinoxMidSummerSolstice/2_Data/BCS_data/Measure_01/processed_images",
)
)
image_file = ft.norm_path(os.path.join(indir, "20230512_113032.81 5W01_000_880_2890 Raw_Testing_Peak_Flux.png"))

style = rcps.RenderControlPointSeq(markersize=10)
fiducials = PointFiducials(style, points=p2.Pxy(np.array([[0, 643, 1000], [0, 581, 1000]])))
operable = SpotAnalysisOperable(CacheableImage(source_path=image_file), given_fiducials=[fiducials])

processor = AnnotationImageProcessor()
result = processor.process_image(operable)[0]
img = result.primary_image.nparray

plt.figure()
plt.imshow(img)
plt.show(block=True)
bbean23 marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is nice

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! It's really handy for this sort of situation where:

  • you're going to be using lots of random classes
  • they all have the same name so it's easy to tell which package they came from

Original file line number Diff line number Diff line change
@@ -4,6 +4,7 @@
from opencsp.common.lib.cv.spot_analysis.image_processor.AbstractSpotAnalysisImageProcessor import (
AbstractSpotAnalysisImagesProcessor,
)
from opencsp.common.lib.cv.spot_analysis.image_processor.AnnotationImageProcessor import AnnotationImageProcessor
from opencsp.common.lib.cv.spot_analysis.image_processor.AverageByGroupImageProcessor import (
AverageByGroupImageProcessor,
)
@@ -29,6 +30,7 @@
__all__ = [
'AbstractAggregateImageProcessor',
'AbstractSpotAnalysisImagesProcessor',
'AnnotationImageProcessor',
'AverageByGroupImageProcessor',
'ConvolutionImageProcessor',
'CroppingImageProcessor',