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

How to handle uint8/[0,255] format HSI? #1599

Open
HaleySchuhl opened this issue Sep 17, 2024 · 4 comments
Open

How to handle uint8/[0,255] format HSI? #1599

HaleySchuhl opened this issue Sep 17, 2024 · 4 comments
Labels
enhancement Enhancements to existing features update Updates an existing feature/method

Comments

@HaleySchuhl
Copy link
Contributor

Start a discussion about anything you would like
So far plantcv has added support for a handful of different hyper/multispectral image formats (#972, #956, #781) and @rayn-alex brought up a formatting incompatibility that could make sense to handle automatically.

"It might make sense to introduce a cast to float, possibly already in read_data depending on the input data type. So the Spectral_data objects are always float32/0-1. The RAYN Vision System camera for example produces uint8/0-255 multispectral images and I need to convert to float32 and rescale them to 0-1 in my pcv workflows because otherwise the results do not make sense."

This sounds like a good argument to cast Spectral_data during read_data, or even inside _find_closest / other ideas ??

@HaleySchuhl HaleySchuhl added enhancement Enhancements to existing features update Updates an existing feature/method labels Sep 17, 2024
@github-project-automation github-project-automation bot moved this to New Issues in PlantCV4 Sep 17, 2024
@rayn-alex
Copy link
Collaborator

I think it makes more sense in read_data because then all Spectral_data objects have the same array data type. Is there anything against that?

I guess the only argument against needless conversion is the floating-point error, but I guess it's negligible for these applications, right?

@rayn-alex
Copy link
Collaborator

Here is a sample image from the RVS Camera
sample_set.zip

@HaleySchuhl
Copy link
Contributor Author

Thank you @rayn-alex this is super helpful. And my apologies for my slower response. I would agree that handling various datatypes as soon as possible makes the most sense, and we can evaluate if the decimal accuracy has an impact practically on results.

How do you currently convert your images into a "plantcv friendly datatype" ?

@rayn-alex
Copy link
Collaborator

No worries.

Just like this:

spectral_data = readimage(filename=img_file, mode='envi')
spectral_data.array_data = spectral_data.array_data.astype("float32")  # required for further calculations
if spectral_data.d_type == np.uint8:  # only convert if data seems to be uint8
    spectral_data.array_data = spectral_data.array_data / 255  # convert 0-255 (orig.) to 0-1 range
        

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancements to existing features update Updates an existing feature/method
Projects
Status: New Issues
Development

No branches or pull requests

2 participants