Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
device, maskedb_thresh1 = pcv.binary_threshold(masked_b1, 170, 255, 'light', device, args.debug)
device, ab1 = pcv.logical_or(maskeda_thresh1, maskedb_thresh1, device, args.debug)
device, ab_cnt1 = pcv.logical_or(maskeda_thresh1, maskedb_thresh1, device, args.debug)
device, ab_fill1 = pcv.fill(ab1, ab_cnt1, 300, device, args.debug)
device, roi2, roi_hierarchy2= pcv.define_roi(masked2,'rectangle', device, None, 'default', args.debug,True, 1700, 0,0,0)
device, id_objects2,obj_hierarchy2 = pcv.find_objects(masked2, ab_fill, device, args.debug)
device,roi_objects2, hierarchy2, kept_mask2, obj_area2 = pcv.roi_objects(masked2,'cutto',roi2,roi_hierarchy2,id_objects2,obj_hierarchy2,device, args.debug)
device, masked4 = pcv.apply_mask(masked2, kept_mask2, 'white', device, args.debug)
device, masked_a2 = pcv.rgb2gray_lab(masked4, 'a', device, args.debug)
device, masked_b2 = pcv.rgb2gray_lab(masked4, 'b', device, args.debug)
device, maskeda_thresh2 = pcv.binary_threshold(masked_a2, 122, 255, 'dark', device, args.debug)
device, maskedb_thresh2 = pcv.binary_threshold(masked_b2, 170, 255, 'light', device, args.debug)
device, ab2 = pcv.logical_or(maskeda_thresh2, maskedb_thresh2, device, args.debug)
device, ab_cnt2 = pcv.logical_or(maskeda_thresh2, maskedb_thresh2, device, args.debug)
device, ab_fill2 = pcv.fill(ab2, ab_cnt2, 200, device, args.debug)
device, ab_cnt3 = pcv.logical_or(ab_fill1, ab_fill2, device, args.debug)
device, masked3 = pcv.apply_mask(masked2, ab_cnt3, 'white', device, args.debug)
# Identify objects
device, id_objects3,obj_hierarchy3 = pcv.find_objects(masked2, ab_fill, device, args.debug)
# Define ROI
device, roi3, roi_hierarchy3= pcv.define_roi(masked2,'rectangle', device, None, 'default', args.debug,True, 650, 0,-450,-250)
# Decide which objects to keep and combine with objects overlapping with black bars
device,roi_objects3, hierarchy3, kept_mask3, obj_area1 = pcv.roi_objects(img,'cutto',roi3,roi_hierarchy3,id_objects3,obj_hierarchy3,device, args.debug)
device, kept_mask4_1 = pcv.logical_or(ab_cnt3, kept_mask3, device, args.debug)
device, kept_cnt = pcv.logical_or(ab_cnt3, kept_mask3, device, args.debug)
device, kept_mask4 = pcv.fill(kept_mask4_1, kept_cnt, 200, device, args.debug)
device, soil_car1 = pcv.binary_threshold(masked_a, 128, 255, 'dark', device, debug)
device, soil_car2 = pcv.binary_threshold(masked_a, 128, 255, 'light', device, debug)
device, soil_car = pcv.logical_or(soil_car1, soil_car2, device, debug)
device, soil_masked = pcv.apply_mask(brass_masked, soil_car, 'white', device, debug)
# Convert RGB to LAB and extract the Green-Magenta and Blue-Yellow channels
device, soil_a = pcv.rgb2gray_lab(soil_masked, 'a', device, debug)
device, soil_b = pcv.rgb2gray_lab(soil_masked, 'b', device, debug)
# Threshold the green-magenta and blue images
device, soila_thresh = pcv.binary_threshold(soil_a, 124, 255, 'dark', device, debug)
device, soilb_thresh = pcv.binary_threshold(soil_b, 148, 255, 'light', device, debug)
# Join the thresholded saturation and blue-yellow images (OR)
device, soil_ab = pcv.logical_or(soila_thresh, soilb_thresh, device, debug)
device, soil_ab_cnt = pcv.logical_or(soila_thresh, soilb_thresh, device, debug)
# Fill small objects
device, soil_cnt = pcv.fill(soil_ab, soil_ab_cnt, 300, device, debug)
# Apply mask (for vis images, mask_color=white)
device, masked2 = pcv.apply_mask(soil_masked, soil_cnt, 'white', device, debug)
# Identify objects
device, id_objects, obj_hierarchy = pcv.find_objects(masked2, soil_cnt, device, debug)
# Define ROI
device, roi1, roi_hierarchy = pcv.define_roi(img, 'rectangle', device, None, 'default', debug, True, 600, 450, -600,
-350)
# Decide which objects to keep
device, roi_objects, hierarchy3, kept_mask, obj_area = pcv.roi_objects(img, 'partial', roi1, roi_hierarchy,
# Dilate to join small objects with larger ones
device, ab_cnt1=pcv.dilate(ab_fill1, 3, 2, device, args.debug)
device, ab_cnt2=pcv.dilate(ab_fill1, 3, 2, device, args.debug)
# Fill dilated image mask
device, ab_cnt3=pcv.fill(ab_cnt2,ab_cnt1,150,device,args.debug)
device, masked2 = pcv.apply_mask(masked, ab_cnt3, 'white', device, args.debug)
# Convert RGB to LAB and extract the Green-Magenta and Blue-Yellow channels
device, masked2_a = pcv.rgb2gray_lab(masked2, 'a', device, args.debug)
device, masked2_b = pcv.rgb2gray_lab(masked2, 'b', device, args.debug)
# Threshold the green-magenta and blue images
device, masked2a_thresh = pcv.binary_threshold(masked2_a, 127, 255, 'dark', device, args.debug)
device, masked2b_thresh = pcv.binary_threshold(masked2_b, 128, 255, 'light', device, args.debug)
device, ab_fill = pcv.logical_or(masked2a_thresh, masked2b_thresh, device, args.debug)
# Identify objects
device, id_objects,obj_hierarchy = pcv.find_objects(masked2, ab_fill, device, args.debug)
# Define ROI
device, roi1, roi_hierarchy= pcv.define_roi(masked2,'rectangle', device, None, 'default', args.debug,True, 525, 0,-490,-150)
# Decide which objects to keep
device,roi_objects, hierarchy3, kept_mask, obj_area = pcv.roi_objects(img,'partial',roi1,roi_hierarchy,id_objects,obj_hierarchy,device, args.debug)
# Object combine kept objects
device, obj, mask = pcv.object_composition(img, roi_objects, hierarchy3, device, args.debug)
############## Analysis ################
# Find shape properties, output shape image (optional)
device, soil_car1 = pcv.binary_threshold(masked_a, 128, 255, 'dark', device, args.debug)
device, soil_car2 = pcv.binary_threshold(masked_a, 128, 255, 'light', device, args.debug)
device, soil_car=pcv.logical_or(soil_car1, soil_car2,device, args.debug)
device, soil_masked = pcv.apply_mask(brass_masked, soil_car, 'white', device, args.debug)
# Convert RGB to LAB and extract the Green-Magenta and Blue-Yellow channels
device, soil_a = pcv.rgb2gray_lab(soil_masked, 'a', device, args.debug)
device, soil_b = pcv.rgb2gray_lab(soil_masked, 'b', device, args.debug)
# Threshold the green-magenta and blue images
device, soila_thresh = pcv.binary_threshold(soil_a, 124, 255, 'dark', device, args.debug)
device, soilb_thresh = pcv.binary_threshold(soil_b, 148, 255, 'light', device, args.debug)
# Join the thresholded saturation and blue-yellow images (OR)
device, soil_ab = pcv.logical_or(soila_thresh, soilb_thresh, device, args.debug)
device, soil_ab_cnt = pcv.logical_or(soila_thresh, soilb_thresh, device, args.debug)
# Fill small objects
device, soil_cnt = pcv.fill(soil_ab, soil_ab_cnt, 200, device, args.debug)
# Median Filter
#device, soil_mblur = pcv.median_blur(soil_fill, 5, device, args.debug)
#device, soil_cnt = pcv.median_blur(soil_fill, 5, device, args.debug)
# Apply mask (for vis images, mask_color=white)
device, masked2 = pcv.apply_mask(soil_masked, soil_cnt, 'white', device, args.debug)
# Identify objects
device, id_objects,obj_hierarchy = pcv.find_objects(masked2, soil_cnt, device, args.debug)
# Define ROI
device, roi1, roi_hierarchy= pcv.define_roi(img,'rectangle', device, None, 'default', args.debug,True, 600,450,-600,-350)
# Join the thresholded saturation and blue-yellow images
device, bs = pcv.logical_and(s_mblur, b_cnt, device, args.debug)
# Apply Mask (for vis images, mask_color=white)
device, masked = pcv.apply_mask(img, bs, 'white', device, args.debug)
# Convert RGB to LAB and extract the Green-Magenta and Blue-Yellow channels
device, masked_a = pcv.rgb2gray_lab(masked, 'a', device, args.debug)
device, masked_b = pcv.rgb2gray_lab(masked, 'b', device, args.debug)
# Threshold the green-magenta and blue images
device, maskeda_thresh = pcv.binary_threshold(masked_a, 127, 255, 'dark', device, args.debug)
device, maskedb_thresh = pcv.binary_threshold(masked_b, 128, 255, 'light', device, args.debug)
# Join the thresholded saturation and blue-yellow images (OR)
device, ab = pcv.logical_or(maskeda_thresh, maskedb_thresh, device, args.debug)
device, ab_cnt = pcv.logical_or(maskeda_thresh, maskedb_thresh, device, args.debug)
# Fill small noise
device, ab_fill1 = pcv.fill(ab, ab_cnt, 2, device, args.debug)
# Dilate to join small objects with larger ones
device, ab_cnt1=pcv.dilate(ab_fill1, 3, 2, device, args.debug)
device, ab_cnt2=pcv.dilate(ab_fill1, 3, 2, device, args.debug)
# Fill dilated image mask
device, ab_cnt3=pcv.fill(ab_cnt2,ab_cnt1,150,device,args.debug)
device, masked2 = pcv.apply_mask(masked, ab_cnt3, 'white', device, args.debug)
# Convert RGB to LAB and extract the Green-Magenta and Blue-Yellow channels
device, masked2_a = pcv.rgb2gray_lab(masked2, 'a', device, args.debug)
device, masked2_b = pcv.rgb2gray_lab(masked2, 'b', device, args.debug)
# device, masked_erd_dil = pcv.apply_mask(img, dil_img, 'black', device, args.debug)
# Need to remove the edges of the image, we did that by generating a set of rectangles to mask the edges
# img is (254 X 320)
# mask for the bottom of the image
device, box1_img, rect_contour1, hierarchy1 = pcv.rectangle_mask(img, (128,226), (192,252), device, args.debug)
# mask for the left side of the image
device, box2_img, rect_contour2, hierarchy2 = pcv.rectangle_mask(img, (1,1), (75,252), device, args.debug)
# mask for the right side of the image
device, box3_img, rect_contour3, hierarchy3 = pcv.rectangle_mask(img, (245,1), (318,252), device, args.debug)
# mask the edges
device, box4_img, rect_contour4, hierarchy4 = pcv.border_mask(img, (1,1), (318,252), device, args.debug)
# combine boxes to filter the edges and car out of the photo
device, bx12_img = pcv.logical_or(box1_img, box2_img, device, args.debug)
device, bx123_img = pcv.logical_or(bx12_img, box3_img, device, args.debug)
device, bx1234_img = pcv.logical_or(bx123_img, box4_img, device, args.debug)
device, inv_bx1234_img = pcv.invert(bx1234_img, device, args.debug)
# Make a ROI around the plant, include connected objects
# Apply the box mask to the image
# device, masked_img = pcv.apply_mask(masked_erd_dil, inv_bx1234_img, 'black', device, args.debug)
device, edge_masked_img = pcv.apply_mask(masked_erd, inv_bx1234_img, 'black', device, args.debug)
device, roi_img, roi_contour, roi_hierarchy = pcv.rectangle_mask(img, (120,75), (200,226), device, args.debug)
plant_objects, plant_hierarchy = cv2.findContours(edge_masked_img,cv2.RETR_TREE,cv2.CHAIN_APPROX_NONE)
device, roi_objects, hierarchy5, kept_mask, obj_area = pcv.roi_objects(img, 'partial', roi_contour, roi_hierarchy, plant_objects, plant_hierarchy, device, args.debug)
device, ab_fill1 = pcv.fill(ab1, ab_cnt1, 200, device, args.debug)
device, roi2, roi_hierarchy2= pcv.define_roi(masked2,'rectangle', device, None, 'default', args.debug,True, 1900, 0,0,0)
device, id_objects2,obj_hierarchy2 = pcv.find_objects(masked2, ab_fill, device, args.debug)
device,roi_objects2, hierarchy2, kept_mask2, obj_area2 = pcv.roi_objects(masked2,'cutto',roi2,roi_hierarchy2,id_objects2,obj_hierarchy2,device, args.debug)
device, masked4 = pcv.apply_mask(masked2, kept_mask2, 'white', device, args.debug)
device, masked_a2 = pcv.rgb2gray_lab(masked4, 'a', device, args.debug)
device, masked_b2 = pcv.rgb2gray_lab(masked4, 'b', device, args.debug)
device, maskeda_thresh2 = pcv.binary_threshold(masked_a2, 122, 255, 'dark', device, args.debug)
device, maskedb_thresh2 = pcv.binary_threshold(masked_b2, 170, 255, 'light', device, args.debug)
device, ab2 = pcv.logical_or(maskeda_thresh2, maskedb_thresh2, device, args.debug)
device, ab_cnt2 = pcv.logical_or(maskeda_thresh2, maskedb_thresh2, device, args.debug)
device, ab_fill2 = pcv.fill(ab2, ab_cnt2, 200, device, args.debug)
device, ab_cnt3 = pcv.logical_or(ab_fill1, ab_fill2, device, args.debug)
device, masked3 = pcv.apply_mask(masked2, ab_cnt3, 'white', device, args.debug)
# Identify objects
device, id_objects3,obj_hierarchy3 = pcv.find_objects(masked2, ab_fill, device, args.debug)
# Define ROI
device, roi3, roi_hierarchy3= pcv.define_roi(masked2,'rectangle', device, None, 'default', args.debug,True, 525, 0,-500,-900)
# Decide which objects to keep and combine with objects overlapping with black bars
device,roi_objects3, hierarchy3, kept_mask3, obj_area1 = pcv.roi_objects(img,'cutto',roi3,roi_hierarchy3,id_objects3,obj_hierarchy3,device, args.debug)
device, kept_mask4_1 = pcv.logical_or(ab_cnt3, kept_mask3, device, args.debug)
device, kept_cnt = pcv.logical_or(ab_cnt3, kept_mask3, device, args.debug)
device, kept_mask4 = pcv.fill(kept_mask4_1, kept_cnt, 200, device, args.debug)
device, masked5 = pcv.apply_mask(masked2, kept_mask4, 'white', device, args.debug)
device, id_objects4,obj_hierarchy4 = pcv.find_objects(masked5, kept_mask4, device, args.debug)
device, roi4, roi_hierarchy4= pcv.define_roi(masked2,'rectangle', device, None, 'default', args.debug,False, 0, 0,0,0)
device, bs = pcv.logical_and(s_fill, b_fill, device, args.debug)
# Apply Mask (for vis images, mask_color=white)
device, masked = pcv.apply_mask(img, bs,'white', device, args.debug)
# Mask pesky brass piece
device, brass_mask1 = pcv.rgb2gray_hsv(brass_mask, 'v', device, args.debug)
device, brass_thresh = pcv.binary_threshold(brass_mask1, 0, 255, 'light', device, args.debug)
device, brass_inv=pcv.invert(brass_thresh, device, args.debug)
device, brass_masked = pcv.apply_mask(masked, brass_inv, 'white', device, args.debug)
# Further mask soil and car
device, masked_a = pcv.rgb2gray_lab(brass_masked, 'a', device, args.debug)
device, soil_car1 = pcv.binary_threshold(masked_a, 128, 255, 'dark', device, args.debug)
device, soil_car2 = pcv.binary_threshold(masked_a, 128, 255, 'light', device, args.debug)
device, soil_car=pcv.logical_or(soil_car1, soil_car2,device, args.debug)
device, soil_masked = pcv.apply_mask(brass_masked, soil_car, 'white', device, args.debug)
# Convert RGB to LAB and extract the Green-Magenta and Blue-Yellow channels
device, soil_a = pcv.rgb2gray_lab(soil_masked, 'a', device, args.debug)
device, soil_b = pcv.rgb2gray_lab(soil_masked, 'b', device, args.debug)
# Threshold the green-magenta and blue images
device, soila_thresh = pcv.binary_threshold(soil_a, 124, 255, 'dark', device, args.debug)
device, soilb_thresh = pcv.binary_threshold(soil_b, 148, 255, 'light', device, args.debug)
# Join the thresholded saturation and blue-yellow images (OR)
device, soil_ab = pcv.logical_or(soila_thresh, soilb_thresh, device, args.debug)
device, soil_ab_cnt = pcv.logical_or(soila_thresh, soilb_thresh, device, args.debug)
# Fill small objects
device, soil_cnt = pcv.fill(soil_ab, soil_ab_cnt, 250, device, args.debug)
device, maskedb_thresh1 = pcv.binary_threshold(masked_b1, 170, 255, 'light', device, args.debug)
device, ab1 = pcv.logical_or(maskeda_thresh1, maskedb_thresh1, device, args.debug)
device, ab_cnt1 = pcv.logical_or(maskeda_thresh1, maskedb_thresh1, device, args.debug)
device, ab_fill1 = pcv.fill(ab1, ab_cnt1, 300, device, args.debug)
device, roi2, roi_hierarchy2= pcv.define_roi(masked2,'rectangle', device, None, 'default', args.debug,True, 1700, 0,0,0)
device, id_objects2,obj_hierarchy2 = pcv.find_objects(masked2, ab_fill, device, args.debug)
device,roi_objects2, hierarchy2, kept_mask2, obj_area2 = pcv.roi_objects(masked2,'cutto',roi2,roi_hierarchy2,id_objects2,obj_hierarchy2,device, args.debug)
device, masked4 = pcv.apply_mask(masked2, kept_mask2, 'white', device, args.debug)
device, masked_a2 = pcv.rgb2gray_lab(masked4, 'a', device, args.debug)
device, masked_b2 = pcv.rgb2gray_lab(masked4, 'b', device, args.debug)
device, maskeda_thresh2 = pcv.binary_threshold(masked_a2, 122, 255, 'dark', device, args.debug)
device, maskedb_thresh2 = pcv.binary_threshold(masked_b2, 170, 255, 'light', device, args.debug)
device, ab2 = pcv.logical_or(maskeda_thresh2, maskedb_thresh2, device, args.debug)
device, ab_cnt2 = pcv.logical_or(maskeda_thresh2, maskedb_thresh2, device, args.debug)
device, ab_fill2 = pcv.fill(ab2, ab_cnt2, 200, device, args.debug)
device, ab_cnt3 = pcv.logical_or(ab_fill1, ab_fill2, device, args.debug)
device, masked3 = pcv.apply_mask(masked2, ab_cnt3, 'white', device, args.debug)
# Identify objects
device, id_objects3,obj_hierarchy3 = pcv.find_objects(masked2, ab_fill, device, args.debug)
# Define ROI
device, roi3, roi_hierarchy3= pcv.define_roi(masked2,'rectangle', device, None, 'default', args.debug,True, 650, 0,-450,-300)
# Decide which objects to keep and combine with objects overlapping with black bars
device,roi_objects3, hierarchy3, kept_mask3, obj_area1 = pcv.roi_objects(img,'cutto',roi3,roi_hierarchy3,id_objects3,obj_hierarchy3,device, args.debug)
device, kept_mask4_1 = pcv.logical_or(ab_cnt3, kept_mask3, device, args.debug)
device, kept_cnt = pcv.logical_or(ab_cnt3, kept_mask3, device, args.debug)
device, kept_mask4 = pcv.fill(kept_mask4_1, kept_cnt, 200, device, args.debug)
# Join the thresholded saturation and blue-yellow images
device, bs = pcv.logical_and(s_fill, b_fill, device, args.debug)
# Apply Mask (for vis images, mask_color=white)
device, masked = pcv.apply_mask(img, bs, 'white', device, args.debug)
# Convert RGB to LAB and extract the Green-Magenta and Blue-Yellow channels
device, masked_a = pcv.rgb2gray_lab(masked, 'a', device, args.debug)
device, masked_b = pcv.rgb2gray_lab(masked, 'b', device, args.debug)
# Threshold the green-magenta and blue images
device, maskeda_thresh = pcv.binary_threshold(masked_a, 122, 255, 'dark', device, args.debug)
device, maskedb_thresh = pcv.binary_threshold(masked_b, 133, 255, 'light', device, args.debug)
# Join the thresholded saturation and blue-yellow images (OR)
device, ab = pcv.logical_or(maskeda_thresh, maskedb_thresh, device, args.debug)
device, ab_cnt = pcv.logical_or(maskeda_thresh, maskedb_thresh, device, args.debug)
# Fill small objects
device, ab_fill = pcv.fill(ab, ab_cnt, 200, device, args.debug)
# Apply mask (for vis images, mask_color=white)
device, masked2 = pcv.apply_mask(masked, ab_fill, 'white', device, args.debug)
# Identify objects
device, id_objects,obj_hierarchy = pcv.find_objects(masked2, ab_fill, device, args.debug)
# Define ROI
device, roi1, roi_hierarchy= pcv.define_roi(img,'rectangle', device, None, 'default', args.debug,True, 0, 0,0,-900)
# Decide which objects to keep
device,roi_objects, hierarchy3, kept_mask, obj_area = pcv.roi_objects(img,'partial',roi1,roi_hierarchy,id_objects,obj_hierarchy,device, args.debug)