How to realize the effect of Bitmap Segmentation by Python
This article mainly explains "Python how to achieve the effect of bitmap segmentation". The explanation content in this article is simple and clear, easy to learn and understand. Please follow the idea of Xiaobian slowly and deeply to study and learn "Python how to achieve the effect of bitmap segmentation" together!
No more words, just code.
import cv2import numpy as npimport matplotlib.pyplot as pltimg = cv2.imread('Fig3.13.jpg', 0)imgBS = np.zeros_like(img)plt.figure("Image")plt.subplot(2, 4, 1)plt.imshow(img, cmap='gray')plt.axis('off')plt.title('original')for n in range(1, 8): for x in range(img.shape[0]): for y in range(img.shape[1]): gray = img[x, y] & pow(2, n-1) if gray == pow(2, n-1): imgBS[x, y] = 255 else: imgBS[x, y] = 0 plt.subplot(2, 4, n+1) plt.imshow(imgBS, cmap='gray') plt.axis('off') plt.title(str(n) + 'bit') plt.show() Thank you for reading, the above is the content of "Python how to achieve the effect of bitmap segmentation", after learning this article, I believe everyone on Python how to achieve the effect of bitmap segmentation This problem has a deeper understanding, the specific use of the situation also needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!