Python numpy implementation of gray image segmentation and merging

Time:2021-5-7

I don’t want to talk much nonsense. Let’s go straight to the code!

from numpy import *
import numpy as np
import cv2, os, math, os.path
from PIL import Image
base="F:\Spy_CNN\pythonCode\cvSPY\cvTest\LBP\LBPImag3\"
base2="F:\ProgrameCode\FaceDataLib\orl_Arry\"
imageOld=cv2.imread(base2+"s1_1.bmp")
image=cv2.cvtColor(imageOld,cv2.COLOR_BGR2GRAY)
Synthesis of image
H,W=image.shape#(112, 92)
kuai=5
A = 1 # in order to adjust the program
maskx,masky = H/kuai,W/kuai  #29 14
toImage=np.zeros((H+(kuai-1)*a,W+(kuai-1)*a))
toImage.shape

#You can draw a picture and sum up the rules

for i in range(kuai):
    for j in range(kuai):
        '''float64 array'''
        faceZi=image[int(i*maskx): int((i+1)*maskx),int(j*masky) :int((j+1)*masky)]
        cv2.imwrite(base+str(i)+str(j)+".bmp",faceZi)
#        toImage[int(i*maskx)+a: int((i+1)*maskx)+a,int(j*masky)+a :int((j+1)*masky)+a]=faceZi  
        toImage[int(i*maskx)+i: int((i+1)*maskx)+i,int(j*masky)+j :int((j+1)*masky)+j]=faceZi            
cv2.imwrite(base+"toImage.bmp",toImage)
#The simplest is to draw a black line directly on the gray image, but some pixel data will be lost
for i in range(1,kuai):
    print(i)
    toImage[int(i*maskx),:]=0
    toImage[:,int(i*masky)]=0
cv2.imwrite(base+"toImage.bmp",toImage)

The above Python numpy implementation of gray image segmentation and merging is the whole content shared by Xiaobian. I hope it can give you a reference, and I hope you can support developer more.

Recommended Today

The bootstrap form label and input are displayed on one line

The bootstrap version used in this article is 4.4.1 1. Use form inline <form action=””> <div class=”form-group”> <div class=”form-inline”> < label class = “mb-2” > specification value: < / label > < input class = “form control MR-2 mb-2” type = “text” placeholder = “e.g. white” / > < input class = “form control MR-2 […]