美文网首页
Python_(OpenCV, 计算机视觉, MATLAB, 机

Python_(OpenCV, 计算机视觉, MATLAB, 机

作者: yuanthu | 来源:发表于2020-05-18 22:39 被阅读0次

    Python is very popular in this uneven world. Here I would like to present some useful tips and resultful methods I have learned from this (May 18th, 2020) busy afternoon.

    1. Python is a kind of Interpretive language (解释性语言), which mistreats the encoding and decoding in compiled form language as the same processing. It is an easy fore python to transplant to other platforms, and all we need to do is offer the corresponding interpreter.
    2. The choices of training in coding with python are Sublime text, Pycharm; Xcode; Jupyter notebook, and MATLAB from my point of view.
    3. MATLAB could efficiently employ python_modules for utilizing the processes as follows:
    • Download Anaconda-Navigator (python很有用的kits打包软件);
    • pyenv('path_of _anaconda');
    • module_func1 = py.importlib.import_module('func1');
    • Using py.cv2.module_func1
    1. As for Sublime Text, you should define the system environment first: Tools-->Build System --> New Build environment -->
    {
    "cmd': ["python3", "-u", "$file"] #$file refers to current file
    }
    
    1. After cv2.imshow, the following codes should be added to guarantee a sufficient display time:
    delay_time = -1
    cv2.waitKey(delay_time)
    cv2.destoryAllWindows()
    
    1. Images Convolution (2D or 3D) should be utilized with deconvolution and down-sampling & up-sampling.
    2. cv2 (OpenCV) has many bit-wise functions that are very useful in masking images and image segmentation.
    3. The color space HSV means Hue, saturation, and value, and it is corresponding to human vision. Moreover, it is practicable in selection with a specified color range.
    cv2.cvtColor(inputArray, outputArray, COLOR_BGR2GRAY)
    
    1. YCrCb colour space is very favourable in illumination correction.
    2. cv2 has a very fantastic function named remap.
    3. The Gaussian kernel is a universally used prior probabilistic model.
    4. cv2.morphologyEx() helps process with methods in morphology. The processing includes cv2.MORPH_ERODE (膨胀), cv2.MORPH_DILATE (腐蚀), cv2.MORPH_OPEN (开运算), cv2.CLOSE (闭运算), cv2.MORPH_GRADIENT (形态梯度运算), cv2.MORPH_TOPHAT (顶帽运算), cv2.MORPH_BLACKHAT (黑帽运算) and cv2.MORPH_HITMISS (击中与否).
    5. Scharr operator is similar to the Sobel operator, and the purpose should determine the operator's choice. For example, I wanted to find the intersection of two perpendicular directions, then Sobel is an excellent choice to deal with this issue. However, if I want to see the edges, which are also a response to the weak signals, I woulD like to choose the hessian operator or the canny operator.
    6. Scale-space, cv2.pyrDown() (下采样) and cv2.pyr.Up() (上采样), by the way, they are not inverse to each other. Laplacian pyramid = G_i - pyrUp(G_{i +1}). We can restore the images by employing the Laplacian pyramid and the corresponding downsampled images.
    7. cv2.findContours() is employed in detecting contour of image. This function will return a structure with hierarchy and contours and images
    8. Contour moments include some useful details, such as spacial moments, central moments, and HU moments. Additionally, HU moments could help in judging whether two images are similar or not.
      Ps: HU moments are the linear combination of normalized central moments. The consistent characters of the moments are maintained even if there are transformations such as rotating, scaling, and translating. (这里没有 affine 的不变)
    9. There are some convenient functions which could help in finding out the polygon to surround the subject contour:
    cv2.boundingrect(contour[n]) #rectangle boundary, by the way, contour[n] means the results (contour) by using *findContour* with the index n. The contour[n] is actually a set with some points included.
    cv2.minAreaRect(contour[n]) #surrounding with minimum rectangle
    cv2.minEnclosingCircle(contour[n]) #闭环圆圈包围
    cv2.fitEllipse(contour[n])# 椭圆包围
    cv2.fitLine(contour[n], distance_type, parameters, radial_precision, angular_precision)
    
    1. The cv2.drawContours() could help in drawing a line along the contours which is come from the results of the findContours().
      Besides, we can set the thickness of cv2.drawContours() as -1 to guarantee the contours are drawn with solid lines.
      We can use the Numpy to find out the location information of the labelled points, and the codes are as follows:
    import NumPy as np
    mask = np.zeros(gray.shape, np.uint8)# init mask
    cv2.drawContours(mask,[target _shape], 0, 255, -1) #draw contours to the target_shpe
    pixelPoints = np.transpose(np.nonzero(contour_line))
    print(f’pixel points = {pixelPoints}’)
    
    1. The modules denominated with matplotlib.pyplot could assist in plotting the 2D line-plot and the profile of the data array. Additionally, the hist, which is employed to draw the histogram of the 2D array, in matplotlib could be called by dot syntax (点语法).
    2. signal processing in the Fourier domain is more convenient and has more efficient computation than processing in the spatial-temporal area. What's more, it is useful in making the signals look more like the signals.
      我理解的, 其实时域与频域的不确定关系可以这么理解, 当一个信号拥有十分简单的结构外观, 那么他一定可以被很简单预测, 这也就是这个信号的频域十分简单; 除此之外, 如果这个信号十分复杂在时域, 那么他一定很难复制, 也就是对应相对较短的频域, 也就是很难通过他目前的states来预测未来.
    3. 我之前会用很多 C 与 MATLAB写一些图像算法, 现在更多用Python和Swift, 而MATLAB会经常用于建模, 最大感觉是Python, Swift, MATLAB好像没有哪里不好反而很实用. 其实我理解, 对于图像而言, 算法本质在于化简模型; 而化简模型本质在于高效分割. 图像的segmentation 有a lot of universally applicable methods 比较火的是 scale-space这是CNN的基础; 还有马尔科夫场, 我理解的markov random field是一种池化pooling, 他的结果就是点亮了局部feather(s);其实图割法 (graph-cut), 应该是一种special MRF; 还有就是很有名的灰度特征向量, the crucial is to arrange the grey space into a specified subset, in this wise, the statistic points in the same scope are arranged into an array, and the array is considered as a vector, and the vector is a kind of feature vector (tensor); 有个Ostu方法就是依赖于这样的统计的空间张量, 还有直方图均值化 (直方图均衡化其实就是HVS,human Visual System的视觉概率平滑), Bi-Gaussian mode, deformable module (基于灰度张量的力场分析), dense correspondence, and adaptive filter... 太多了, 在Python里直方图用numpy绘制:
    import cv2
    import matplotlib.pyplot as plt
    image = cv2.imread('image_path')
    plt.hist(image.ravel(),256)
    cv2.waitKey()
    cv2.destoryAllWindows
    

    Besides, 使用

    hist = cv2.calHist(image, channels, mask, histSize, ranges, accumulate)
    

    来计算图像的统计直方图.

    Keep going

    相关文章

      网友评论

          本文标题:Python_(OpenCV, 计算机视觉, MATLAB, 机

          本文链接:https://www.haomeiwen.com/subject/esvxhhtx.html