Package: imagerie
ImagerieLightweight python package grouping together useful computer vision functions and operationsThis package was initially created for myself to extract some of the most useful important functions,from packages likescipy,skimage, etc...This was done in order to expose all these very useful computer vision functions,and be able to use them in aServerlessenvironment.DocumentationPrerequisitesThis package only supportspython3today.Only tested onpython3.6andpython3.7InstallationInstall using pippip install imagerie.Functionsimagerie.get_rotation(pt1, pt2)Returns the rotation value in degrees between 2 (x,y) points.imagerie.order_points(points)You've guessed it, this function simply sorts a list of 4 [x, y] coordinates in a clockwise manner, starting from the top-left.imagerie.remove_lonely_small_objects(grayscale)This function removes small white objects from a binary mask.imagerie.remove_smaller_objects(grayscale)Finds all contours and removes them all except the biggest one.imagerie.biggest_contour(grayscale)Finds and retrieves the biggest contour from a grayscale image.imagerie.get_biggest_contour(contours)Simply retrieves and returns the biggest contour from a given list of contours.imagerie.closest_point(point: tuple, points)Returns the closest (x, y) point from a given list of (x, y) points/coordinates.imagerie_lite.midpoint(ptA, ptB)Calculates the X,Y middle points from provided 2 points.imagerie_lite.line_intersection(line1: tuple, line2: tuple)Returns the intersection point between two lines.imagerie.get_corners(grayscale, middle_points=False, centroid=False, max_corners=4, quality_level=0.01, min_distance=15)Returns the (x, y) coordinates of the 4 corners of a rectangular shaped object from binary mask by default.
However, you can also calculate the top and bottom middle coordinates by providingmiddle_points=True.
And by providintcentroid=True, you can get the (x, y) coordinates of the center.imagerie.warp_perspective(image, src_pts: list, dst_pts: list)Performs acv2.warpPerspective()operation and expects 2 lists of (x, y) corner points of the source
and destination image.imagerie.warp_homography(image, src_pts: list, dst_pts: list, method=cv2.RANSAC, reproj_threshold=5.0)Performs acv2.warpPerspective()operation aftercv2.findHomography().imagerie.image_composite_with_mask(to_add: PIL.Image.Image, destination: PIL.Image.Image, mask: PIL.Image.Image)Combines theto_addanddestinationimages,to_addimage will be added on top ofdestinationimage
and only the white area from themaskimage will be retained fromto_addimage.imagerie.combine_two_images_with_mask(background_img, foreground_img, mask)Combines the images with the help of the provided mask.
Note that only the white area of the mask will be selected from theforeground_img.imagerie.prepare_for_prediction_single(img, shape=(768, 768), as_array=True)Loads and resizes a single image to a given shape (default: 768, 768) and returns it by default as a numpy array.imagerie.prepare_for_prediction(imgs, shape=(768, 768))Does the same thing asimagerie.prepare_for_prediction_singlebut for multiple images.imagerie.fill_holes(gray_img: ndarray, min=200, max=255)Fills black pixel holes that reside inside of a binary object.minrepresents thethreshused incv2.threshold(gray, thresh=200, ...).maxrepresents themaxvalused incv2.threshold(gray, maxval=255, ...).imagerie.img_as_uint(img)Converts image to 16 bit unsigned integer format.imagerie.img_as_float(img)Convert an image to floating point format.imagerie.normalize_binary_img(img: np.ndarray)Very useful when re-converting a predicted binary mask img to original grayscale format.CreditsIbragim Abubakarov<ibragim.ai95@gmail.com>