plantcv icon indicating copy to clipboard operation
plantcv copied to clipboard

pixel to cm conversion function

Open kmurphy61 opened this issue 2 years ago • 2 comments

Problem: Every time I analyze data from a PlantCV output, I have to convert all the measurements from pixels to cm, based on the output size of the color card. This will save time and user errors in downstream analysis, as some users do not convert units correctly.

Solution: A new function that takes the following inputs: median_color_chip_height (already output from the find_color_card function), units are pixels color_chip_height_cm (input manually from the user based on the color card they are using), units are in cm shape_outputs (from analyze_shape function, such as area, height, etc.), units are in pixels

The function will use the following for height, etc: shape_output_pixels*color_chip_height_cm/median_color_chip_height = shape_output_cm

For area, use the following: shape_output_pixels^2color_chip_height_cm/median_color_chip_heightcolor_chip_height_cm/median_color_chip_height = shape_output_cm^2

The function will output: Any shape measurements, such as height, area, etc., as usual, but will also output the converted to cm. For example, right now the output looks like this: Trait: area, value: 10350, label: pixels

And the new output would add or replace with the following: Trait: area, value: 148, label: cm

Thank you!

kmurphy61 avatar Jul 29 '22 16:07 kmurphy61

I think that's a good idea. The capability to calculate and save these scaled measurements is possible with steps like this:

plant_area = pcv.outputs.observations['default']['pixel_area']['value']
chip_area = pcv.outputs.observations['default']['color_chip_size']['value']
scaled_area = plant_area / chip_area
# Create a new measurement
pcv.outputs.add_observation(sample='default', variable='area_cm', 
                            trait='object area in cm squared',
                            method='standardize pixel measurements using color card size', scale='cm^2', 
                            datatype=float, value=scaled_area, label='percent')

This is certainly tedious in the case of standardizing the many measurements collected by analyze_object so I think it would bring a lot of value if we had the functionality to convert/standardize all "pixel" measurements within a workflow.

HaleySchuhl avatar Jul 29 '22 18:07 HaleySchuhl

I could imagine three potential implementations:

  1. New calibration input to analyze_* functions (downside is more inputs = bad)
  2. When a calibration function is run the calibration value(s) are stored in pcv.params (e.g. find_color_card, report_size_marker) and utilized by analyze_* functions (plus the user could just set it if they had another source for the calibration value(s). Maybe somewhat a black box (but documented)?
  3. New calibration function that operates on pcv.outputs. One downside here is that there has to be logic for handling all the different kinds of measurements - i.e. is it a length, an area, or something we should not try to calibrate, might be easier to handle it at the point of recording rather than later.

nfahlgren avatar Jul 29 '22 18:07 nfahlgren