5.6. PikaCV Image Processing Libraries
Add the dependency of PikaCV to requestment.txt.
Run pikaPackage.exe
5.6.2. Import
Add in main.py:
import PikaCV as cv
The Image class is the basis of the PikaCV,and subsequent image processing algorithms are based on the Image class.By creating an object of the Image class,an empty image can be created.Such as:
PikaCV can read Jpeg format files and write bmp format files.
def read(self, path: str):
"""Read the image from the specified path,
and `__platform_fclose()`"""
...
def write(self, path: str):
"""Write the image to the specified path,
Need implement the `__platform_fopen()`, `__platform_fwrite()`
and `__platform_fclose()`"""
...
def loadJpeg(self, bytes: any):
"""Load the image from bytes"""
def loadRGB888(self, width: int, height: int, bytes: bytes):
"""Load the image from bytes"""
def loadGray(self, width: int, hight: int, bytes: bytes):
"""Load the image from bytes"""
The size
of an image is width * hight * channel
。
add()
andminus()
is pixel-by-pixel operation.When the result of the operation exceeds 255, it is classified as 255, and when it is below 0, it is classified as 0.The channel order is RGB in
merge()
andsplit()
5.6.4. class Converter():
Converter class mainly implements the conversion between image formats, and currently Converter supports the following image storage formats and conversions
-
means no action,*
means that an intermediate transformation is required, √
means that it can be converted directly
An example of an image format conversion operation is as follows:
cv.Converter.toBMP(img)
rotateDown(image: Image)
This function can rotates the image by 180 degrees.
-
This function is used to convert an image to a binary image.
thre
:When the value of the thresholdType is 0-4, thre is used as the demarcation threshold for the imagethresholdType
: Threshold type, which means as follows: setROI(image:Image,x:int,y:int,w:int,h:int)
This function is used to select a ROI from an image, the definition of the area is xywh,
x
andy
represent the upper left vertex coordinates of the region,w
represents the width of the area, andh
represents the height of the area.getOTSUthre(image:Image) -> int
This function implements OTSU,For the specific principle, please participate in the paper, the return value of the function is the threshold calculated by the OTSU method.
-
This function uses the OTSU algorithm to binaryize the image.
resize(image:Image,x:int,y:int,resizeType:int)
This function implements the scaling of the image, with x and y being the target size of the image
resizeType
:The scaling method of the image. 0 represents the nearest neighbor algorithm.adaptiveThreshold(image:Image,maxval:int,subsize:int,c:int,method:int)
method
:An algorithm used to calculate the threshold within a neighborhood. 0 represents mean filtering, 1 represents median filtering.c
:offset valuesubsize
: Convolutional kernel size
5.6.6. class Filter
The Filter class implements some commonly used image filtering algorithms, and the algorithms that have been implemented so far are:
meanFilter(image:Image,ksizex:int,ksizey:int)
Mean filtering, ksizex and ksizey are the size of x and y of the convolutional kernels, respectively. There is currently no support for pads, so the size of the image after filtering equal
W-F+1
when .