Package: mask2bbox
mask2bboxFor a given mask, gets the coordinates of bounding box of each element of the mask. It will also allow for more operations in the future.Instalationpipinstallmask2bboxCLIpython-mmask2bbox-hUsageimportnumpyasnpfrommask2bboximportBBoxes# Create a BBoxes objectall_boxes=BBoxes.from_mask("path/to/mask.png")# Expand the bounding boxesall_boxes=all_boxes.expand(n=10)# Remove the bounding boxes that are located on the edge of the imageall_boxes=all_boxes.remove_from_edge()# Get the sides of all the bounding boxessides=all_boxes.get("sides")# Filter the bounding boxes by the sidesfiltered_boxes=all_boxes.filter("sides",np.greater_equal,(35,35))# Get the IoU matrix of all the bounding boxesiou=filtered_boxes.iou_matrix()# Save the overlapping pairs tofiltered_boxes.save_overlapping_pairs("path/to/save/overlapping_pairs.csv")# Save the IOU matrix to a csv filefiltered_boxes.save_iou_matrix("path/to/save/iou_matrix.csv")# Plot the bounding boxes on the mask imagefiltered_boxes.draw(to="image",method="matplotlib",show="False",save="path/to/save/image.png")# Save your bounding boxesfiltered_boxes.save_csv("path/to/bounding_boxes.csv")# Get resize factors to resize the bounding boxes to a given sizeresize_factors=filtered_boxes.de(desired_ratio=0.7,size=(256,256))# Extract the bounding boxes as imagesfiltered_boxes.extract(resize_factors,size=(256,256),output="path/to/save/images")Version Notes0.0.14 - UpdateUpdate:Remove LICENSERenameBBoxes.save_iou()toBBoxes.save_overlapping_pairs()in the CLI.ConvertBBoxes._helper_box_drawer()to static method.Add:Add logger to the package.AddBBoxes.sample()to get a random sample of the bounding boxes.AddBBoxes.save_iou_matrix()to save the IoU matrix to a csv file.Add-osto the CLI to save a sample of the isolated nuclei instead of the whole set.Add-logto speciy the log level in the CLI (Options are: info and debug).0.0.13 - UpdateUpdate:Change setup.py to pyproject.toml.Add:Added entry points to the package to allow for CLI usage.Added dynamic versioning to the packageversion.pyalso accessible from the CLIpython -m mask2bbox -v.0.0.12 - UpdateUpdate:BBoxes.from_mask()now accepts an image parameter as an additional input, this removes the need of having to load the image separately.__getitem__magic attribute indexes based on the cell/mask id (making it base 1 instead of base 0).ReplacedBBoxes.extract_single()andBBoxes.grab()-> withBBoxes.grab_pixels_from()BBoxes.grab_pixels_from()gets the pixels from the image/mask that are inside the bounding boxes.BBoxes.grab_pixels_from()makes optional the processing steps implemented inBBoxes.extract().0.0.11 - Added functionalityAddedBBoxes.grab()Replacedplot_to_mask()andBBoxes.plot_to_image()-> withBBoxes.draw()BBoxes.draw()allows to plot the bounding boxes on the mask or the image.BBoxes.draw()allows to choose betweenmatplotlibandnumpyto generate the plot.ModifiedBBoxes.extract_single()BBoxes.extract_single()adds pre-processing steps such asBBoxes.extract()0.0.10 - Added functionalityAddedextract_single(): This method allows to extract a single bounding box form the image/mask.Added check toBBoxes.from_mask(): Now the method checks if the mask contains any element or not and raises an error if it doesn't.0.0.9 - Fix bug inBBoxes.extract()Fix bug inBBoxes.extract()that caused the images to be saved with the wrong name amd created a new folder.0.0.8 - Change methods, change constructor, added functionality.Constructor:BBox object is now constructed with the syntaxBBoxes.from_mask(mask)instead ofBBoxes(mask).Operations:BBox object operations are no longer performed in place, the affected methods are:BBoxes.remove_from_edge()BBoxes.expand()BBoxes.filter()Removed methods:is_area_smaller_than()is_area_larger_than()are_dims_smaller_than()are_dims_larger_than()filter_identities()These methods used in-place operations and are no longer needed, they were substituted with.Renamed:BBoxes.get_bbox_areas()->BBoxes.get_areas()BBoxes.get_bbox_dims()->BBoxes.get_sizes()BBoxes.get_bbox_centers()->BBoxes.get_centers()BBoxes.get_bbox_ratios()->BBoxes.get_ratios()New methods:BBoxes.filter():This method allows to filter the bounding boxes by any of the attributes in the object specifying the comparison operator and threshold value. It returns a new BBoxes object with the filtered values.BBoxes.get():This method allows to get the values of the attributes in the object. It works as a simplification toBBoxes.get_areas(),BBoxes.get_centers(),BBoxes.get_sizes()andBBoxes.get_ratios().BBoxes.extract():This new method isolates the bounding boxes as images and saves them to the desired location.BBoxes.calculate_resizing_factor():This method calculates the resizing factor needed to resize the bounding boxes to a given size.BBoxes._pad_crop():Helper method to pad or crop the bounding boxes to a desired output size.BBoxes.plot_to_image():This method plots the bounding boxes to the corresponding image and saves it to the desired location.0.0.7 - Improved functionalityImprovements in IoU calculation0.0.6 - Added functionality0.0.5 - Added functionalityIoU related operations:boxes.get_iou_matrix()- Gets the IoU of all the bounding boxes.boxes.are_overlaping()- Returns identities where the IoU is greater than 0boxes.overlaping_pais()- Returns the pairs of bounding boxes that are overlaping.boxes.save_iou()- Saves the IoU matrix to a csv file.Plotsboxes.plot_to_mask()Plots the bounding boxes on the mask image.Example ofboxes.plot_to_mask()0.0.4 - Added functionalityNow is possible to extract:Bounding boxes dimensionsBBoxes.get_bbox_dims()Bounding boxes areaBBoxes.get_bbox_areas()Bounding boxes centerBBoxes.get_bbox_centers()Bounding boxes ratiosBBoxes.get_bbox_ratios()0.0.3 - Added functionalityAdded the remove_edge_boxes method to remove the bounding boxes that are located on the edge of the image.0.0.2 - Added the expand method to expand the bounding boxes by a given number of pixels.Added the expand method to expand the bounding boxes by a given number of pixels.Fixed a bug in the setup.py file that made it hard to import the package.0.0.1 - Initial release of the package.Initial release of the package. It allows to get the bounding boxes of a mask and save them to a csv file.