Package: coat
CoatCoatis small wrapper that sits onnumpy's ndarray (subclassed) andopencvCoat's only purpouse is for rapid prototypingStyleCoatis using method cascadingreturn from every method isCoat's HigherCoating instanceOnly exception is method classic() which returns back numpy instance\Installpreferably use virtual envpipinstallcoatDemofunctionCoatis a proxy function that handles different types of args.It handles str(url), list/generator of images and ndarray.fromcoatimportCoaturl="https://natgeo.imgix.net/subjects/headers/shutterstock_276228476.jpg?auto=compress,format&w=1920&h=960&fit=crop"Coat(url).thresh(125,255).show()UsageContentCore functionalitiesDominanceArray manipulationImage downloadingLabelingColor spacesHelper functionsMontageContoursColor filteringMotion differenceCore functionalitiesLets define two arrays of different type, size and dimension# Import Coat(proxy function) and MontagefromcoatimportCoat,Montageimportnumpyasnparray1=Coat(np.zeros(shape=[40,60,3],dtype=np.uint8))array2=Coat(np.zeros(shape=[8,8],dtype=np.float32))Auto resolverCoating the arrays you letCoatresolve array operations whenever there is conflictres=array1+array2res.shape,res.dtype>>>(40,60,3)uint8Coated arrays can be dominant or non-dominant.
General rules are as follows:A(non-dominant)+B(non-dominant)->Aisprioritized
A(non-dominant)+B(dominant)->Bisprioritized
A(dominant)+B(non-dominant)->Aisprioritized
A(dominant)+B(dominant)->AisprioritizedDominance settingYou can set which array is dominant
Be default each array is not dominant.res=array1*array2.host()res.shape,res.dtype>>>(8,8)float32If have arrays of different size and dimension( gray & colored), you can simply transform to common standard as followslist_of_images=[img1,img2,img3,..,..,imgN]# define common standardgrayscale_template=Coat(np.zeros(shape=[100,100],dtype=np.uint8))colored_template=Coat(np.zeros(shape=[100,100],dtype=np.uint8))grascaled=[grayscale_template.host()+imageforimageinlist_of_images]colored=[colored_template.host()+imageforimageinlist_of_images]interpolationYou can set interpolation algorithm (default is LINEAR - BILINEAR)res=array1-array2.host('CUBIC')Removing dominanceres=array1*array2.host('CUBIC').guest()res.shape,res.dtype>>>(40,60,3)uint8Array manipulationosize as objective sizearray1.shape,array2.shape>>>(40,60,3),(8,8)array1.osize(array2.shape).shape>>>(8,8,3)array2.osize(array1.shape).shape>>>(40,60)rsize as relative sizeres=array2.rsize(fx=2,fy=0.5)res.shape>>>(16,4)ndarray compatibilityres=array1+np.zeros(shape=array1.shape)np.uint8(array1)# -> returns back Coat instance with changed datatypearray1.classic()# -> returns back numpy instanceLeveraging OpenCVDownload imagepass url to Coat andshowiturl="https://natgeo.imgix.net/subjects/headers/shutterstock_276228476.jpg?auto=compress,format&w=1920&h=960&fit=crop"image=Coat(url).show()image=image.rsize(fx=0.25,fy=0.25)Supports labeling# Use int for objective coordinatesimage.labelbox("Home",(0,136),(230,340),bcolor=[0,255,0]).show()# Use float for relative coordinatesimage.labelbox("Home",(0.0,0.3),(0.9,0.7),bcolor=[0,255,0]).show()Colorspace changesupported color transformationBGR2GRAY
BGR2HLS
BGR2HSV
HSV2BGR
GRAY2RGB
GRAY2BGR
RGB2GRAY
RGB2HSV
RGB2HLSimage.color_to('BGR2GRAY')NOTEOpenCV is using BGR as default color schemeImage processing helpersThresholdimage.thresh(125,255,'thresh_binary').show()Convolution filteringimage.blur_medianimage.filter_bilateralimage.blur_gaussimage.blur_averageConvolution 2Dimg.conv(kernel)MontageSee orignal next to processed imagewe add host (turn on dominance of first image) so we get result in RGB colorspace as our original image is rgbimage.rsize(fx=0.3,fy=0.3).host().join(image.thresh(127,255)).show()Montage of different color spacesimg=image.rsize(fx=0.3,fy=0.3)color_spaces=["BGR2GRAY","BGR2HLS","BGR2HSV",]Dominant is the first image if template is not definedall_images=[img]+[img.to_color(cspace)forcspaceincolor_spaces]montage=Montage(all_images).grid(2,2).show()resize montage based on templatemontage=Montage(all_images).template(np.zeros(shape=[50,50,3],dtype=np.uint8)).grid(2,2)Remove stars with morphological openingimage.morphologyEx('open',3).show()Contours# Draw quick countoursthr=image.thresh(200,255)# copycontoured=image.copy().contours(thr,min_size=5,max_size=9999999,thickness=2,color=[0,125,255]).show()Replace particular colorpresent=[0,125,255]future=[255,0,0]contoured.replace(present,future).show()Color filtering# [36,0,0] --> green color interval in HSV <--[70,255,255]image.filterHsv([36,0,0],[70,255,255],passband=True).show()image.filterHsv([36,0,0],[70,255,255],passband=False).show()# Passband False:   -------|++|-----# Passband True:   ++++++|--|++++++passband Truepassband FalseMotion differencebox1=Coat(np.zeros(shape=[400,400,3])).box((30,30),(250,250),color=[255,125,0])box2=Coat(np.zeros(shape=[400,400,3])).box((30,150),(250,350),color=[255,125,0])motion_diff=box1.motion_difference(box2,val=30).show()