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

Improve binary datatype checks #1635

Open
33 tasks
HaleySchuhl opened this issue Nov 18, 2024 · 2 comments
Open
33 tasks

Improve binary datatype checks #1635

HaleySchuhl opened this issue Nov 18, 2024 · 2 comments
Labels
enhancement Enhancements to existing features good first issue/PR Suitable for a first time contributor/reviewer help wanted Request help update Updates an existing feature/method

Comments

@HaleySchuhl
Copy link
Contributor

HaleySchuhl commented Nov 18, 2024

Start a discussion about anything you would like
Many of the functions that take binary images as input will check that the input data is indeed binary. In some cases that means checking for the number of unique values to be exactly 2 (0, and 255 represented). But there are cases (pcv.fill_holes and maybe others?) where an empty mask is valid to pass through.

Look for and update the logic in these bin-img datatype checks.

  • List of functions to update --> Current check
  • pcv.fill_holes --> if len(np.shape(bin_img)) != 2 or len(np.unique(bin_img)) != 2
  • pcv.closing --> if len(np.shape(gray_img)) != 2 or if len(np.unique(gray_img)) == 2
  • pcv.crop_position_mask --> if len(np.shape(mask)) == 3 then mask = mask[0]
  • pcv.fill --> if len(np.shape(bin_img)) != 2 or len(np.unique(bin_img)) > 2
  • pcv.flood_fill --> if len(np.shape(bin_img)) != 2 or len(np.unique(bin_img)) != 2

List of functions NOT currently doing datatype checks

  • pcv.apply_mask does not check the mask but checks the img
  • pcv.auto_crop
  • pcv.background_subtraction only checking for equal image sizes and resizes if not
  • pcv.canny_edge_detect no check on mask but checks img by if len(dimensions) == 3 then img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
  • pcv.create_labels no check on mask and scikit.measure.label will run on an RGB image but will fatally error while trying to plot the labeled mask.
  • pcv.dilate no current check on gray_img, and actually the source depth can be greater than one so possible to use on RGB?
  • pcv.distance_transform no current check on bin_img
  • pcv.erode no current check on gray_img, and actually the source depth can be greater than one so possible to use on RGB?
  • pcv.image_add no current check on gray image inputs, but also will work when images are not grayscale.
  • pcv.invert does not currently check gray_img but the wrapped cv2 function bitwise_not can accept RGB data also.
  • pcv.laplace_filter no current check on gray_img but accepts RGB data also.
  • pcv.logical_and no current check on bin_img and the underlying cv2. bitwise_and can accept RGB data.
  • pcv.logical_or no current check on bin_img and the underlying cv2. bitwise_or can accept RGB data.
  • pcv.logical_xor no current check on bin_img and the underlying cv2. bitwise_xor can accept RGB data.
  • pcv.median_blur no current check on gray_img but underlying scipy.ndimage.median_filter can accept RGB data.
  • pcv.naive_bayes_classifier no current check on rgb_img but would fatally err if grayscale image input.
  • pcv.rgb2gray_cymk, pcv.rgb2gray_hsv, pcv.rgb2gray_lab, pcv.rgb2gray no current check on rgb_img
  • pcv.sobel_filter no current check on gray_img
  • pcv.spatial_clustering no current check on mask
  • pcv.watershed no current check on mask
  • pcv.filters.obj_props no current check on bin_img
  • pcv.filters.eccentricity no current check on bin_img
  • pcv.morphology.check_cycles no current check on skel_img but should be binary otherwise will err on cv2 step.
    • find_tips, find_branch_pts, prune, segment_id, segment_skeleton, segment_sort,
  • pcv.morphology.fill_segments no current check on mask
  • pcv.transform.affine_color_correction no current check on rgb_img but would give an error about number of objects if somehow given a gray or bin_img
  • pcv.transform.find_color_card no check on rgb_img
  • pcv.visualize.obj_sizes no check on mask

Example of good dtype checks

  • pcv.hist_equalization --> if len(np.shape(gray_img)) == 3 then fatal error.
  • pcv.image_subtract --> if len(np.shape(gray_img1)) != 2 or len(np.shape(gray_img2)) != 2
  • pcv.predict_kmeans --> if len(train_img.shape) == 2: # gray and elif len(train_img.shape) == 3 and train_img.shape[2] == 3: # rgb
  • pcv.opening --> if len(np.shape(gray_img)) != 2: then fatal error, # If image is binary use the faster method
    if len(np.unique(gray_img)) == 2: and otherwise use grayscale friendly algorithm
  • pcv.within_frame --> len(np.shape(mask)) > 2 or len(np.unique(mask)) > 2: fatal_error("Mask should be a binary image
  • All of the pcv.analyze.___ functions --> # Skip empty masks if np.count_nonzero(mask) != 0:
  • pcv.photosynthesis.reassign_frame_labels --> checks mask to be binary and the same size as the other input img. if mask.shape != ps_da.shape[:2] or len(np.unique(mask)) > 2: fatal_error(f"Mask needs to be binary and have shape {ps_da.shape[:2]}")
@HaleySchuhl HaleySchuhl added enhancement Enhancements to existing features update Updates an existing feature/method labels Nov 18, 2024
@HaleySchuhl
Copy link
Contributor Author

HaleySchuhl commented Nov 20, 2024

@all-contributors please add @jbraley1107 for bug

Thanks for bringing this "no object" error to our attention so we can make these various other functions "fail" gracefully and informatively.

Copy link
Contributor

@HaleySchuhl

I've put up a pull request to add @jbraley1107! 🎉

@HaleySchuhl HaleySchuhl added help wanted Request help good first issue/PR Suitable for a first time contributor/reviewer labels Dec 3, 2024
@github-project-automation github-project-automation bot moved this to New Issues in PlantCV4 Dec 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancements to existing features good first issue/PR Suitable for a first time contributor/reviewer help wanted Request help update Updates an existing feature/method
Projects
Status: New Issues
Development

No branches or pull requests

1 participant