Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize the effect of Bitmap Segmentation by Python

Shulou Source: shulou.com Published: 2022-06-02 13:08:05 09月22日 Update

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!

Tags: Bitmaps effects learning content code that is ideas situations articles more knowledge knowledge points articles follow questions practice push research verification Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Huawei MySQL Apple Microsoft