Automatically detect a color card and color correct in one step

Corrects the color of the input image based on the target color matrix using an affine transformation in the RGB space after automatic detection of a color card within the image. A one-step wrapper of plantcv.transform.detect_color_card, plantcv.transform.std_color_matrix, plantcv.transform.get_color_matrix, and plantcv.transform.affine_color_correction.

plantcv.transform.auto_correct_color(rgb_img, label=None, **kwargs)

returns corrected_img

  • Parameters
    • rgb_img - Input RGB image data containing a color card.
    • label - Optional label parameter, modifies the variable name of observations recorded. (default = pcv.params.sample_label)
    • **kwargs - Other keyword arguments passed to cv2.adaptiveThreshold and cv2.circle.
      • adaptive_method - Adaptive threhold method. 0 (mean) or 1 (Gaussian) (default = 1).
      • block_size - Size of a pixel neighborhood that is used to calculate a threshold value (default = 51). We suggest using 127 if using adaptive_method=0.
      • radius - Radius of circle to make the color card labeled mask (default = 20).
      • min_size - Minimum chip size for filtering objects after edge detection (default = 1000)
  • Returns

    • corrected_img - Color corrected image
  • Example Use

    • Below

from plantcv import plantcv as pcv

rgb_img, imgpath, imgname = pcv.readimage(filename="top_view_plant.png")

corrected_rgb = pcv.transform.auto_correct_color(rgb_img=old_card)

Debug Image: automatically detected and masked the color card

Screenshot

Source Code: Here