Java教程

【无标题】数值计算

本文主要是介绍【无标题】数值计算,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
import cv2
# import numpy as np
# import matplotlib.pyplot as plt

img=cv2.imread('D:/bridge.jpg')#读出一张彩色图
bridge=img[0:50,0:200]#切片操作
bridge[:,:,0]=0
bridge[:,:,1]=0#索引0,1,2对应颜色通道b,g,r
cv2.imshow('image',bridge)
cv2.waitKey(0)
cv2.destroyWindow('image')

import cv2
img_bridge=cv2.imread('D:/bridge.jpg')
img_cartoon=cv2.imread('D:/cartoon.jpg')
print(img_cartoon[:5,:,0])#单颜色通道切片
img_cartoon2=img_cartoon+10
print(img_cartoon2[:5,:,0])
print(img_cartoon[:5,:,0]+img_cartoon2[:5,:,0])#取模256运算
print(cv2.add(img_cartoon[:5,:,0],img_cartoon2[:5,:,0]))#opencv的add()做矩阵运算,超过255取255
print(img_cartoon.shape,img_bridge.shape)
img_cartoon=cv2.resize(img_cartoon,(960,1280))#改变图片尺寸便于相加
print(img_cartoon.shape,img_bridge.shape)
img_=img_cartoon+img_bridge
cv2.imshow('image',img_)
cv2.waitKey(0)
cv2.destroyWindow('image')

输出

[[160 160 160 ... 160 160 160]
 [160 160 160 ... 160 160 160]
 [160 160 160 ... 160 160 160]
 [160 160 160 ... 160 160 160]
 [160 160 160 ... 160 160 160]]
[[170 170 170 ... 170 170 170]
 [170 170 170 ... 170 170 170]
 [170 170 170 ... 170 170 170]
 [170 170 170 ... 170 170 170]
 [170 170 170 ... 170 170 170]]
[[74 74 74 ... 74 74 74]
 [74 74 74 ... 74 74 74]
 [74 74 74 ... 74 74 74]
 [74 74 74 ... 74 74 74]
 [74 74 74 ... 74 74 74]]
[[255 255 255 ... 255 255 255]
 [255 255 255 ... 255 255 255]
 [255 255 255 ... 255 255 255]
 [255 255 255 ... 255 255 255]
 [255 255 255 ... 255 255 255]]
(1921, 889, 3) (1280, 960, 3)
(1280, 960, 3) (1280, 960, 3)

这篇关于【无标题】数值计算的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!