Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# 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,
id_objects, obj_hierarchy, device, debug)
# Object combine kept objects
device, obj, mask = pcv.object_composition(img, roi_objects, hierarchy3, device, debug)
# Find shape properties, output shape image (optional)
device, shape_header, shape_data, shape_img = pcv.analyze_object(img, vis_img, obj, mask, device, debug)
# Determine color properties
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,-650,-120)
# 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 = pcv.logical_or(ab_cnt3, kept_mask3, device, args.debug)
device, masked5 = pcv.apply_mask(masked2, kept_mask4, 'white', device, args.debug)
device, masked5_a = pcv.rgb2gray_lab(masked5, 'a', device, args.debug)
device, masked5_a_thresh = pcv.binary_threshold(masked5_a, 130, 255, 'light', device, args.debug)
device, masked5_a_cnt = pcv.binary_threshold(masked5_a, 130, 255, 'light', device, args.debug)
device, masked5_a_fill = pcv.fill(masked5_a_thresh, masked5_a_cnt, 200, device, args.debug)
device, masked5_mblur = pcv.median_blur(masked5_a_fill, 7, device, args.debug)
device, id_objects4,obj_hierarchy4 = pcv.find_objects(masked5, masked5_mblur, device, args.debug)
device, roi4, roi_hierarchy4= pcv.define_roi(masked2,'rectangle', device, None, 'default', args.debug,False, 0, 0,0,0)
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
device, soil_mblur = pcv.median_blur(soil_fill, 13, device, args.debug)
device, soil_cnt = pcv.median_blur(soil_fill, 13, device, args.debug)
#
# Apply mask (for vis images, mask_color=white)
device, masked2 = pcv.apply_mask(soil_mblur, 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, 400,400,-400,-400)
#
# 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, shape_header,shape_data,shape_img = pcv.analyze_object(img, args.image, obj, mask, device,args.debug,args.outdir+'/'+filename)
# Determine color properties: Histograms, Color Slices and Pseudocolored Images, output color analyzed images (optional)
# 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, 550, 0,-600,-907)
# 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)
############## VIS Analysis ################
outfile=False
if args.writeimg==True:
outfile=args.outdir+"/"+filename
# 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, 500, 0,-600,-885)
# 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)
############## VIS Analysis ################
outfile=False
if args.writeimg==True:
outfile=args.outdir+"/"+filename
# 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 objects
device, ab_fill = pcv.fill(ab, ab_cnt, 20, 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, 30, 25,-10,-15)
# 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, shape_header,shape_data,shape_img = pcv.analyze_object(img, args.image, obj, mask, device,args.debug,args.outdir+'/'+filename)
# Shape properties relative to user boundary line (optional)
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, 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,roi_objects4, hierarchy4, kept_mask4, obj_area = pcv.roi_objects(img,'partial',roi4,roi_hierarchy4,id_objects4,obj_hierarchy4,device, args.debug)
# Object combine kept objects
device, obj, mask = pcv.object_composition(img, roi_objects4, hierarchy4, device, args.debug)
# Find matching NIR image
device, nirpath=pcv.get_nir(path,filename,device,args.debug)
nir, path1, filename1=pcv.readimage(nirpath)
nir2=cv2.imread(nirpath,-1)
# Flip mask
device, f_mask= pcv.flip(mask,"vertical",device,args.debug)
# Reize mask
device, nmask = pcv.resize(f_mask, 0.116148,0.116148, device, args.debug)
# position, and crop mask
device,newmask=pcv.crop_position_mask(nir,nmask,device,33,3,"top","right",args.debug)
# Identify objects
device, nir_objects,nir_hierarchy = pcv.find_objects(nir, newmask, device, args.debug)
# Object combine kept objects
device, nir_combined, nir_combinedmask = pcv.object_composition(nir, nir_objects, nir_hierarchy, device, args.debug)
####################################### Analysis #############################################
outfile1=False
if args.writeimg==True:
outfile1=args.outdir+"/"+filename1
device,nhist_header, nhist_data,nir_imgs= pcv.analyze_NIR_intensity(nir2, filename1, nir_combinedmask, 256, device,False, args.debug, outfile1)
device, nshape_header, nshape_data, nir_shape = pcv.analyze_object(nir2, filename1, nir_combined, nir_combinedmask, device, args.debug, outfile1)
coresult=open(args.coresult,"a")
coresult.write('\t'.join(map(str,nhist_header)))
coresult.write("\n")
coresult.write('\t'.join(map(str,nhist_data)))
# 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 objects
device, ab_fill = pcv.fill(ab, ab_cnt, 20, 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, 25, 25,-10,-25)
# 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, shape_header,shape_data,shape_img = pcv.analyze_object(img, args.image, obj, mask, device,args.debug,args.outdir+'/'+filename)
# Shape properties relative to user boundary line (optional)
# Find matching NIR image
device, nirpath=pcv.get_nir(path,filename,device,args.debug)
nir, path1, filename1=pcv.readimage(nirpath)
nir2=cv2.imread(nirpath,-1)
# Flip mask
device, f_mask= pcv.flip(mask,"vertical",device,args.debug)
# Reize mask
device, nmask = pcv.resize(f_mask, 0.116148,0.116148, device, args.debug)
# position, and crop mask
device,newmask=pcv.crop_position_mask(nir,nmask,device,36,2,"top","right",args.debug)
# Identify objects
device, nir_objects,nir_hierarchy = pcv.find_objects(nir, newmask, device, args.debug)
# Object combine kept objects
device, nir_combined, nir_combinedmask = pcv.object_composition(nir, nir_objects, nir_hierarchy, device, args.debug)
####################################### Analysis #############################################
outfile1=False
if args.writeimg==True:
outfile1=args.outdir+"/"+filename1
device,nhist_header, nhist_data,nir_imgs= pcv.analyze_NIR_intensity(nir2, filename1, nir_combinedmask, 256, device,False, args.debug, outfile1)
device, nshape_header, nshape_data, nir_shape = pcv.analyze_object(nir2, filename1, nir_combined, nir_combinedmask, device, args.debug, outfile1)
coresult=open(args.coresult,"a")
coresult.write('\t'.join(map(str,nhist_header)))
coresult.write("\n")
coresult.write('\t'.join(map(str,nhist_data)))