diff --git a/docs/cluster_contours.md b/docs/cluster_contours.md index 0cf0ef162..55f40be0f 100644 --- a/docs/cluster_contours.md +++ b/docs/cluster_contours.md @@ -2,7 +2,7 @@ This function take a image with multiple contours and clusters them based on user input of rows and columns -**platncv.cluster_contours**(*img, roi_objects, roi_obj_hierarchy, nrow=1,ncol=1*) +**platncv.cluster_contours**(*img, roi_objects, roi_obj_hierarchy, nrow=1,ncol=1, show_grid=False*) **returns** grouped_contour_indexes, contours, hierarchy @@ -12,6 +12,7 @@ This function take a image with multiple contours and clusters them based on use - roi_obj_hierarchy - object hierarchy - nrow - approximate number of rows (default nrow=1) - ncol - approximate number of columns (default ncol=1) + - show_grid - if True then a grid gets displayed in debug mode (default show_grid=False) - **Context:** - Cluster contours based on number of approximate rows and columns - **Example use:** @@ -32,9 +33,14 @@ pcv.params.debug = "print" # clusters them based on user input of rows and columns clusters_i, contours, hierarchy = pcv.cluster_contours(img, roi_objects, roi_obj_hierarchy, 4, 6) +clusters_i, contours, hierarchy = pcv.cluster_contours(img, roi_objects, roi_obj_hierarchy, 4, 6, show_grid=True) ``` **Cluster Contour Image** ![Screenshot](img/documentation_images/cluster_contour/14_clusters.jpg) +**Cluster Contour Image with Grid** + +![Screenshot](img/documentation_images/cluster_contour/show_grid.jpg) + diff --git a/docs/img/documentation_images/cluster_contour/show_grid.jpg b/docs/img/documentation_images/cluster_contour/show_grid.jpg new file mode 100644 index 000000000..13044b9b5 Binary files /dev/null and b/docs/img/documentation_images/cluster_contour/show_grid.jpg differ diff --git a/docs/multi-plant_tutorial.md b/docs/multi-plant_tutorial.md index 88e17d473..c768197cd 100644 --- a/docs/multi-plant_tutorial.md +++ b/docs/multi-plant_tutorial.md @@ -325,6 +325,8 @@ roi_objects, roi_obj_hierarchy, kept_mask, obj_area = pcv.roi_objects(img1, 'par # roi_obj_hierarchy = object hierarchy # nrow = number of rows to cluster (this should be the approximate number of desired rows in the entire image even if there isn't a literal row of plants) # ncol = number of columns to cluster (this should be the approximate number of desired columns in the entire image even if there isn't a literal row of plants) +# show_grid = if True then a grid gets displayed in debug mode (default show_grid=False) + clusters_i, contours, hierarchies = pcv.cluster_contours(img1, roi_objects, roi_obj_hierarchy, 4, 6) ``` @@ -561,6 +563,7 @@ def main(): # roi_obj_hierarchy = object hierarchy # nrow = number of rows to cluster (this should be the approximate number of desired rows in the entire image even if there isn't a literal row of plants) # ncol = number of columns to cluster (this should be the approximate number of desired columns in the entire image even if there isn't a literal row of plants) + # show_grid = if True then a grid gets displayed in debug mode (default show_grid=False) clusters_i, contours, hierarchies = pcv.cluster_contours(img1, roi_objects, roi_obj_hierarchy, 4, 6) diff --git a/docs/updating.md b/docs/updating.md index fa18ca2df..291d328ff 100644 --- a/docs/updating.md +++ b/docs/updating.md @@ -186,7 +186,7 @@ pages for more details on the input and output variable types. * pre v3.0dev2: device, cropped = **plantcv.auto_crop**(*device, img, objects, padding_x=0, padding_y=0, color='black', debug=None*) * post v3.0dev2: cropped = **plantcv.auto_crop**(*img, objects, padding_x=0, padding_y=0, color='black'*) -* post v3.2: cropped = **plantcv.auto_crop**(*img, obj, padding_x=0, padding_y=0, color='black*) +* post v3.2: cropped = **plantcv.auto_crop**(*img, obj, padding_x=0, padding_y=0, color='black'*) #### plantcv.background_subtraction @@ -202,7 +202,7 @@ pages for more details on the input and output variable types. #### plantcv.canny_edge_detect ** pre v3.2: NA -** post v3.2: bin_img = **plantcv.canny_edge_detect**(*img, mask = None, sigma=1.0, low_thresh=None, high_thresh=None, thickness=1, mask_color=None, use_quantiles=False*) +** post v3.2: bin_img = **plantcv.canny_edge_detect**(*img, mask=None, sigma=1.0, low_thresh=None, high_thresh=None, thickness=1, mask_color=None, use_quantiles=False*) #### plantcv.cluster_contour_splitimg @@ -213,6 +213,7 @@ pages for more details on the input and output variable types. * pre v3.0dev2: device, grouped_contour_indexes, contours, roi_obj_hierarchy = **plantcv.cluster_contours**(*device, img, roi_objects,roi_obj_hierarchy, nrow=1, ncol=1, debug=None*) * post v3.0dev2: grouped_contour_indexes, contours, roi_obj_hierarchy = **plantcv.cluster_contours**(*img, roi_objects, roi_obj_hierarchy, nrow=1, ncol=1*) +* post v3.2: grouped_contour_indexes, contours, roi_obj_hierarchy = **plantcv.cluster_contours**(*img, roi_objects, roi_object_hierarchy, nrow=1, ncol=1, show_grid=False*) #### plantcv.color_palette @@ -539,7 +540,7 @@ post v3.0: new_img = **plantcv.image_subtract**(*gray_img1, gray_img2*) #### plantcv.transform.find_color_card * pre v3.0: NA -* post v3.0: df, start_coord, spacing = **plantcv.transofrm.find_color_card**(*rgb_img, threshold='adaptgauss', threshvalue=125, blurry=False, background='dark'*) +* post v3.0: df, start_coord, spacing = **plantcv.transform.find_color_card**(*rgb_img, threshold='adaptgauss', threshvalue=125, blurry=False, background='dark'*) #### plantcv.transform.get_color_matrix diff --git a/plantcv/plantcv/cluster_contours.py b/plantcv/plantcv/cluster_contours.py index 4c221f2d3..a02ad6772 100755 --- a/plantcv/plantcv/cluster_contours.py +++ b/plantcv/plantcv/cluster_contours.py @@ -7,7 +7,7 @@ from plantcv.plantcv import params -def cluster_contours(img, roi_objects, roi_obj_hierarchy, nrow=1, ncol=1): +def cluster_contours(img, roi_objects, roi_obj_hierarchy, nrow=1, ncol=1, show_grid=False): """ This function take a image with multiple contours and clusters them based on user input of rows and columns @@ -20,8 +20,7 @@ def cluster_contours(img, roi_objects, roi_obj_hierarchy, nrow=1, ncol=1): in the entire image (even if there isn't a literal row of plants) ncol = number of columns to cluster (this should be the approximate number of desired columns in the entire image (even if there isn't a literal row of plants) - file = output of filename from read_image function - filenames = input txt file with list of filenames in order from top to bottom left to right + show_grid = if True then the grid will get plot to show how plants are being clustered Returns: grouped_contour_indexes = contours grouped @@ -31,6 +30,7 @@ def cluster_contours(img, roi_objects, roi_obj_hierarchy, nrow=1, ncol=1): :param roi_objects: list :param nrow: int :param ncol: int + :param show_grid: bool :return grouped_contour_indexes: list :return contours: list :return roi_obj_hierarchy: list @@ -123,7 +123,7 @@ def digitize(a, step): # Debug image is rainbow printed contours - if params.debug == 'print': + if params.debug is not None: if len(np.shape(img)) == 3: img_copy = np.copy(img) else: @@ -137,22 +137,14 @@ def digitize(a, step): pass else: cv2.drawContours(img_copy, roi_objects, a, rand_color[i], -1, hierarchy=roi_obj_hierarchy) - print_image(img_copy, os.path.join(params.debug_outdir, str(params.device) + '_clusters.png')) - - elif params.debug == 'plot': - if len(np.shape(img)) == 3: - img_copy = np.copy(img) - else: - iy, ix = np.shape(img) - img_copy = np.zeros((iy, ix, 3), dtype=np.uint8) - - rand_color = color_palette(len(coordlist)) - for i, x in enumerate(coordlist): - for a in x: - if roi_obj_hierarchy[0][a][3] > -1: - pass - else: - cv2.drawContours(img_copy, roi_objects, a, rand_color[i], -1, hierarchy=roi_obj_hierarchy) - plot_image(img_copy) + if show_grid: + for y in rbreaks: + cv2.line(img_copy, (0, y), (ix, y), (255, 0, 0), params.line_thickness) + for x in cbreaks: + cv2.line(img_copy, (x, 0), (x, iy), (255, 0, 0), params.line_thickness) + if params.debug=='print': + print_image(img_copy, os.path.join(params.debug_outdir, str(params.device) + '_clusters.png')) + elif params.debug=='plot': + plot_image(img_copy) return grouped_contour_indexes, contours, roi_obj_hierarchy diff --git a/tests/tests.py b/tests/tests.py index 2ffdff49d..842a27629 100755 --- a/tests/tests.py +++ b/tests/tests.py @@ -637,7 +637,7 @@ def test_plantcv_cluster_contours(): # Test with debug = "print" pcv.params.debug = "print" _ = pcv.cluster_contours(img=img1, roi_objects=objs, roi_obj_hierarchy=obj_hierarchy, nrow=4, ncol=6) - _ = pcv.cluster_contours(img=img1, roi_objects=objs, roi_obj_hierarchy=obj_hierarchy) + _ = pcv.cluster_contours(img=img1, roi_objects=objs, roi_obj_hierarchy=obj_hierarchy, show_grid=True) # Test with debug = "plot" pcv.params.debug = "plot" _ = pcv.cluster_contours(img=img1, roi_objects=objs, roi_obj_hierarchy=obj_hierarchy, nrow=4, ncol=6)