Package: kwimage
Read the docshttps://kwimage.readthedocs.ioGitlab (main)https://gitlab.kitware.com/computer-vision/kwimageGithub (mirror)https://github.com/Kitware/kwimagePypihttps://pypi.org/project/kwimageThe main webpage for this project is:https://gitlab.kitware.com/computer-vision/kwimageThekwimagemodule handles low-level image operations at a high level.The corekwimageis a functional library with image-related helper
functions that are either unimplemented in or more have a more general
interface then their opencv counterparts.Thekwimagemodule builds onkwarrayand provides tools commonly needed
when addressing computer vision problems. This includes functions for reading
images, resizing, image warp transformations, run-length-encoding, and
non-maximum-suppression.Thekwimagemodule is also the current home of my annotation data
structures, which provide efficient ways to interoperate between different
common annotation formats (e.g. different bounding box / polygon / point
formats).  These data structures have both a.drawand.draw_onmethod
for overlaying visualizations on matplotlib axes or numpy image matrices
respectively.Read the docs at:http://kwimage.readthedocs.io/en/main/The top-level API is:from.algoimport(available_nms_impls,daq_spatial_nms,non_max_supression,)from.im_alphablendimport(ensure_alpha_channel,overlay_alpha_images,overlay_alpha_layers,)from.im_colorimport(Color,)from.im_coreimport(atleast_3channels,ensure_float01,ensure_uint255,exactly_1channel,find_robust_normalizers,make_channels_comparable,normalize,normalize_intensity,num_channels,padded_slice,)from.im_cv2import(connected_components,convert_colorspace,gaussian_blur,gaussian_patch,imcrop,imresize,imscale,morphology,warp_affine,warp_image,warp_projective,)from.im_demodataimport(checkerboard,grab_test_image,grab_test_image_fpath,)from.im_drawimport(draw_boxes_on_image,draw_clf_on_image,draw_header_text,draw_line_segments_on_image,draw_text_on_image,draw_vector_field,fill_nans_with_checkers,make_heatmask,make_orimask,make_vector_field,nodata_checkerboard,)from.im_filterimport(fourier_mask,radial_fourier_mask,)from.im_ioimport(imread,imwrite,load_image_shape,)from.im_runlenimport(decode_run_length,encode_run_length,rle_translate,)from.im_stackimport(stack_images,stack_images_grid,)from.structsimport(Box,Boxes,Coords,Detections,Heatmap,Mask,MaskList,MultiPolygon,Points,PointsList,Polygon,PolygonList,Segmentation,SegmentationList,smooth_prob,)from.transformimport(Affine,Linear,Matrix,Projective,Transform,)from.util_warpimport(add_homog,remove_homog,subpixel_accum,subpixel_align,subpixel_getvalue,subpixel_maximum,subpixel_minimum,subpixel_set,subpixel_setvalue,subpixel_slice,subpixel_translate,warp_points,warp_tensor,)NOTE: THE KWIMAGE STRUCTS MAY? EVENTUALLY MOVE TO THE KWANNOT REPO
(But this transition might take awhile)The most notable feature of thekwimagemodule are thekwimage.structsobjects. This includes the primitiveBoxes,Mask, andCoordsobjects, The
semi-primitivePoints,Polygonstructures, and the compositeHeatmapandDetectionsstructures (note:Heatmapis just a composite of array-like
structures).The primitive and semi-primitive objects store and manipulate annotation
geometry, and the composite structures combine primitives into a single
object that jointly manipulates the primitives usingwarpoperations.TheDetectionsstructure is a meta-structure that associates the other more
primitive components, and allows a developer to compose them into something
that represents objects of interest.  The details of this composition are left
up to the end-application.TheDetectionsobject can also be “rasterized” and converted into aHeatmapobject, which represents the same information, but is in a form that is more
suitable for use when training convolutional neural networks. Likewise, the
output of neural networks can be directly encoded in akwimage.Heatmapobject. TheHeatmap.detectmethod can then be used to convert the dense
heatmap representation into a spareDetectionsrepresentation that is more
suitable for use in an object-detection system. We note that thedetectfunction is not a special detection algorithm. The detection algorithm (which
is outside the scope of kwimage) produces the heatmap, and thedetectmethod
effectively “inverts” therasterizeprocedure ofDetectionsby finding
peaks in the heatmap, and running non-maximum suppression.This module contains data structures for three image annotation primitives:Boxes  # technically this could be made out of Coords, probably not for efficiency and decouplingMask   # likewise this could be renamed to RasterCoords #These primative structures are used to define these metadata-containing composites:DetectionsPolygonHeatmapMultiPolygonPolygonListMaskListAll of these structures have aself.dataattribute that holds a pointer to
the underlying data representation.Some of these structures have aself.formatattribute describing the
underlying data representation.Most of the composite structures also have aself.metaattribute, which
holds user-level metadata (e.g. info about the classes).InstallationThere are a few small quirks with installing kwimage. There is an issue with
the opencv python bindings such that we could rely on either theopencv-pythonoropencv-python-headlesspackage. If you have either of
these module already installed you can simplypip install kwimagewithout
encountering any issues related to this. But if you do not already have a
module that providesimport cv2installed, then you should install kwimage
with one of the following “extra install” tags:# We recommend using the headless versionpipinstallkwimage[headless]# OR# If other parts of your system depend on the opencv qt libs
# (NOT RECOMMENDED: this can conflict with pyqt5)pipinstallkwimage[graphics]Some features also require thekwimage_extpackage to be installed, which
contains binary extensions that used to be distributed with this package in
older versions. These extension can be obtained by explicitlypip install kwimage_extor viapip install kwimage[optional](which also
brings in other optional libraries). You can disable loading of c-extensions at
runtime by setting the environment variable:KWIMAGE_DISABLE_C_EXTENSIONS=1.A Note on GDALThe kwimage library can useGDALlibrary
for certain tasks (e.g. IO of geotiffs).  GDAL can be a pain to install without
relying on conda.  Kitware also has a pypi index that hosts GDAL wheels for
linux systems:pipinstall--find-linkshttps://girder.github.io/large_image_wheelsGDAL