Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# Read image
img, path, filename = pcv.readimage(args.image)
brass_mask = cv2.imread(args.roi)
# Pipeline step
device = 0
# Convert RGB to HSV and extract the Saturation channel
device, s = pcv.rgb2gray_hsv(img, 's', device, args.debug)
# Threshold the Saturation image
device, s_thresh = pcv.binary_threshold(s, 49, 255, 'light', device, args.debug)
#Median Filter
device, s_mblur = pcv.median_blur(s_thresh, 5, device, args.debug)
#Apply Mask (for vis images, mask_color=white)
device, masked = pcv.apply_mask(img, s_mblur, 'white', device, args.debug)
# Convert RGB to LAB and extract the Green-Magenta
device, soil_a = pcv.rgb2gray_lab(masked, 'a', device, args.debug)
#
# Threshold the green-magenta
device, soila_thresh = pcv.binary_threshold(soil_a, 133, 255, 'light', device, args.debug)
device, soila_cnt = pcv.binary_threshold(soil_a, 133, 255, 'light', device, args.debug)
#
# Fill small objects
device, soil_fill = pcv.fill(soila_thresh, soila_cnt, 200, device, args.debug)
#
# Median Filter
# Read image
img, path, filename = pcv.readimage(args.image)
brass_mask = cv2.imread(args.roi)
# Pipeline step
device = 0
# Convert RGB to HSV and extract the Saturation channel
device, s = pcv.rgb2gray_hsv(img, 's', device, args.debug)
# Threshold the Saturation image
device, s_thresh = pcv.binary_threshold(s, 49, 255, 'light', device, args.debug)
# Median Filter
device, s_mblur = pcv.median_blur(s_thresh, 5, device, args.debug)
device, s_cnt = pcv.median_blur(s_thresh, 5, device, args.debug)
# Fill small objects
device, s_fill = pcv.fill(s_mblur, s_cnt, 150, device, args.debug)
# Convert RGB to LAB and extract the Blue channel
device, b = pcv.rgb2gray_lab(img, 'b', device, args.debug)
# Threshold the blue image
device, b_thresh = pcv.binary_threshold(b, 130, 255, 'light', device, args.debug)
device, b_cnt = pcv.binary_threshold(b, 130, 255, 'light', device, args.debug)
# Fill small objects
device, b_fill = pcv.fill(b_thresh, b_cnt, 150, device, args.debug)
# Join the thresholded saturation and blue-yellow images
device, bs = pcv.logical_and(s_fill, b_fill, device, args.debug)
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, 118, 255, 'dark', device, args.debug)
device, soilb_thresh = pcv.binary_threshold(soil_b, 155, 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_fill = pcv.fill(soil_ab, soil_ab_cnt, 50, 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,'circle', device, None, 'default', args.debug,True, 0,0,-50,-50)
# 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)
# Read image
img, path, filename = pcv.readimage(args.image)
brass_mask = cv2.imread(args.roi)
# Pipeline step
device = 0
# Convert RGB to HSV and extract the Saturation channel
device, s = pcv.rgb2gray_hsv(img, 's', device, args.debug)
# Threshold the Saturation image
device, s_thresh = pcv.binary_threshold(s, 49, 255, 'light', device, args.debug)
# Median Filter
device, s_mblur = pcv.median_blur(s_thresh, 5, device, args.debug)
device, s_cnt = pcv.median_blur(s_thresh, 5, device, args.debug)
# Fill small objects
device, s_fill = pcv.fill(s_mblur, s_cnt, 150, device, args.debug)
# Convert RGB to LAB and extract the Blue channel
device, b = pcv.rgb2gray_lab(img, 'b', device, args.debug)
# Threshold the blue image
device, b_thresh = pcv.binary_threshold(b, 138, 255, 'light', device, args.debug)
device, b_cnt = pcv.binary_threshold(b, 138, 255, 'light', device, args.debug)
# Fill small objects
device, b_fill = pcv.fill(b_thresh, b_cnt, 100, device, args.debug)
# Join the thresholded saturation and blue-yellow images
device, bs = pcv.logical_and(s_fill, b_fill, device, args.debug)
# Read image
img, path, filename = pcv.readimage(args.image)
#roi = cv2.imread(args.roi)
# Pipeline step
device = 0
# Convert RGB to HSV and extract the Saturation channel
device, s = pcv.rgb2gray_hsv(img, 's', device, args.debug)
# Threshold the Saturation image
device, s_thresh = pcv.binary_threshold(s, 36, 255, 'light', device, args.debug)
# Median Filter
device, s_mblur = pcv.median_blur(s_thresh, 5, device, args.debug)
device, s_cnt = pcv.median_blur(s_thresh, 5, device, args.debug)
# Fill small objects
device, s_fill = pcv.fill(s_mblur, s_cnt, 0, device, args.debug)
# Convert RGB to LAB and extract the Blue channel
device, b = pcv.rgb2gray_lab(img, 'b', device, args.debug)
# Threshold the blue image
device, b_thresh = pcv.binary_threshold(b, 138, 255, 'light', device, args.debug)
device, b_cnt = pcv.binary_threshold(b, 138, 255, 'light', device, args.debug)
# Fill small objects
device, b_fill = pcv.fill(b_thresh, b_cnt, 150, device, args.debug)
# Join the thresholded saturation and blue-yellow images
device, bs = pcv.logical_and(s_fill, b_fill, device, args.debug)
# Read image
img, path, filename = pcv.readimage(args.image)
#roi = cv2.imread(args.roi)
# Pipeline step
device = 0
# Convert RGB to HSV and extract the Saturation channel
device, s = pcv.rgb2gray_hsv(img, 's', device, args.debug)
# Threshold the Saturation image
device, s_thresh = pcv.binary_threshold(s, 36, 255, 'light', device, args.debug)
# Median Filter
device, s_mblur = pcv.median_blur(s_thresh, 5, device, args.debug)
device, s_cnt = pcv.median_blur(s_thresh, 5, device, args.debug)
# Fill small objects
device, s_fill = pcv.fill(s_mblur, s_cnt, 0, device, args.debug)
# Convert RGB to LAB and extract the Blue channel
device, b = pcv.rgb2gray_lab(img, 'b', device, args.debug)
# Threshold the blue image
device, b_thresh = pcv.binary_threshold(b, 138, 255, 'light', device, args.debug)
device, b_cnt = pcv.binary_threshold(b, 138, 255, 'light', device, args.debug)
# Fill small objects
device, b_fill = pcv.fill(b_thresh, b_cnt, 10, device, args.debug)
# Join the thresholded saturation and blue-yellow images
if args.debug:
pcv.plot_hist(sbx_img, 'hist_sbx')
# 1st derivative sobel filtering along vertical axis, kernel = 1, unscaled)
device, sby_img = pcv.sobel_filter(img, 0, 1, 1, 1, device, args.debug)
if args.debug:
pcv.plot_hist(sby_img, 'hist_sby')
# Combine the effects of both x and y filters through matrix addition
# This will capture edges identified within each plane and emphesize edges found in both images
device, sb_img = pcv.image_add(sbx_img, sby_img, device, args.debug)
if args.debug:
pcv.plot_hist(sb_img, 'hist_sb_comb_img')
# Use a lowpass (blurring) filter to smooth sobel image
device, mblur_img = pcv.median_blur(sb_img, 1, device, args.debug)
device, mblur_invert_img = pcv.invert(mblur_img, device, args.debug)
# combine the smoothed sobel image with the laplacian sharpened image
# combines the best features of both methods as described in "Digital Image Processing" by Gonzalez and Woods pg. 169
device, edge_shrp_img = pcv.image_add(mblur_invert_img, lp_shrp_img, device, args.debug)
if args.debug:
pcv.plot_hist(edge_shrp_img, 'hist_edge_shrp_img')
# Perform thresholding to generate a binary image
device, tr_es_img = pcv.binary_threshold(edge_shrp_img, 150, 255, 'dark', device, args.debug)
# Prepare a few small kernels for morphological filtering
kern = np.zeros((3,3), dtype=np.uint8)
kern1 = np.copy(kern)
kern1[1,1:3]=1
kern2 = np.copy(kern)
# Read image
img, path, filename = pcv.readimage(args.image)
brass_mask = cv2.imread(args.roi)
# Pipeline step
device = 0
# Convert RGB to HSV and extract the Saturation channel
device, s = pcv.rgb2gray_hsv(img, 's', device, args.debug)
# Threshold the Saturation image
device, s_thresh = pcv.binary_threshold(s, 49, 255, 'light', device, args.debug)
# Median Filter
device, s_mblur = pcv.median_blur(s_thresh, 5, device, args.debug)
device, s_cnt = pcv.median_blur(s_thresh, 5, device, args.debug)
# Fill small objects
device, s_fill = pcv.fill(s_mblur, s_cnt, 150, device, args.debug)
# Convert RGB to LAB and extract the Blue channel
device, b = pcv.rgb2gray_lab(img, 'b', device, args.debug)
# Threshold the blue image
device, b_thresh = pcv.binary_threshold(b, 138, 255, 'light', device, args.debug)
device, b_cnt = pcv.binary_threshold(b, 138, 255, 'light', device, args.debug)
# Fill small objects
device, b_fill = pcv.fill(b_thresh, b_cnt, 100, device, args.debug)
# Join the thresholded saturation and blue-yellow images
device, bs = pcv.logical_and(s_fill, b_fill, device, args.debug)
if args.debug:
pcv.plot_hist(sbx_img, 'hist_sbx')
# 1st derivative sobel filtering along vertical axis, kernel = 1, unscaled)
device, sby_img = pcv.sobel_filter(img, 0, 1, 1, 1, device, args.debug)
if args.debug:
pcv.plot_hist(sby_img, 'hist_sby')
# Combine the effects of both x and y filters through matrix addition
# This will capture edges identified within each plane and emphesize edges found in both images
device, sb_img = pcv.image_add(sbx_img, sby_img, device, args.debug)
if args.debug:
pcv.plot_hist(sb_img, 'hist_sb_comb_img')
# Use a lowpass (blurring) filter to smooth sobel image
device, mblur_img = pcv.median_blur(sb_img, 1, device, args.debug)
device, mblur_invert_img = pcv.invert(mblur_img, device, args.debug)
# combine the smoothed sobel image with the laplacian sharpened image
# combines the best features of both methods as described in "Digital Image Processing" by Gonzalez and Woods pg. 169
device, edge_shrp_img = pcv.image_add(mblur_invert_img, lp_shrp_img, device, args.debug)
if args.debug:
pcv.plot_hist(edge_shrp_img, 'hist_edge_shrp_img')
# Perform thresholding to generate a binary image
device, tr_es_img = pcv.binary_threshold(edge_shrp_img, 145, 255, 'dark', device, args.debug)
# Prepare a few small kernels for morphological filtering
kern = np.zeros((3,3), dtype=np.uint8)
kern1 = np.copy(kern)
kern1[1,1:3]=1
kern2 = np.copy(kern)
# Read image
img, path, filename = pcv.readimage(args.image)
#roi = cv2.imread(args.roi)
# Pipeline step
device = 0
# Convert RGB to HSV and extract the Saturation channel
device, s = pcv.rgb2gray_hsv(img, 's', device, args.debug)
# Threshold the Saturation image
device, s_thresh = pcv.binary_threshold(s, 36, 255, 'light', device, args.debug)
# Median Filter
device, s_mblur = pcv.median_blur(s_thresh, 5, device, args.debug)
device, s_cnt = pcv.median_blur(s_thresh, 5, device, args.debug)
# Fill small objects
device, s_fill = pcv.fill(s_mblur, s_cnt, 0, device, args.debug)
# Convert RGB to LAB and extract the Blue channel
device, b = pcv.rgb2gray_lab(img, 'b', device, args.debug)
# Threshold the blue image
device, b_thresh = pcv.binary_threshold(b, 138, 255, 'light', device, args.debug)
device, b_cnt = pcv.binary_threshold(b, 138, 255, 'light', device, args.debug)
# Fill small objects
device, b_fill = pcv.fill(b_thresh, b_cnt, 10, device, args.debug)
# Join the thresholded saturation and blue-yellow images