私はImageからRGB値を差し引く必要があるプロジェクトで作業しています。例では、REDからBLUEチャンネルを減算したいので、REDは減算の差分値を取得します。
外形寸法:1456x2592、 BPP:PythonのImageからRGB値を減算する
[[[ 63 58 60]
[ 63 58 60]
[ 64 59 61]
...,
[155 155 161]
[155 155 161]
[155 155 161]]
[[ 58 53 55]
[ 60 55 57]
[ 62 57 59]
...,
[157 157 163]
[157 157 163]
[158 158 164]]
私はそれらを知っている:3
私が使用している画像は、私に次のようaraysを与える
私は画像の次の性質を持っています画像からの値(RGB)が、今私は(次のサイトから、このコードに基づいて、I)コードhttps://pythonspot.com/en/tag/opencv/
import cv2
import numpy as np
from PIL import Image
# read image into matrix.
m = cv2.imread("ITESO.jpeg")
# get image properties.
h,w,bpp = np.shape(m)
# iterate over the entire image.
# BLUE = 0, GREEN = 1, RED = 2.
for py in range(0,h):
for px in range(0,w):
#m[py][px][2] = 2
n = m[py][px][2] //n takes the value of RED
Y = [n, 0, 0] //I create an array with [RED, 0, 0]
m, Y = np.array(m), np.array(Y)
m = np.absolute(m - Y) //Get the matriz with the substraction
y = 1
x = 1
print (m)
print (m[x][y])
#display image
#cv2.imshow('matrix', m)
#cv2.waitKey(0)
cv2.imwrite('new.jpeg',m)
img = Image.open('new.jpeg')
img.show()
img = Image.open('new.jpeg').convert('L')
img.save('new_gray_scale.jpg')
img.show()
を行うために移動します
私はJのマトリズを印刷するとき、それは次のアレイ与える:
B、G、R
ブルー= BLUE - RED
[[[ 3 58 60]
[ 3 58 60]
[ 4 59 61]
...,
[ 95 155 161]
[ 95 155 161]
[ 95 155 161]]
[[ 2 53 55]
[ 0 55 57]
[ 2 57 59]
...,
[ 97 157 163]
[ 97 157 163]
[ 98 158 164]]
をしかし、私は新しいイメージを開くことaboleありませんよ1つのRGBチャンネルを1つの値に設定すると、画像が表示されます。私はそのために、次の行を使用します。私は、互いからRGBチャンネルを引くことができる方法があるかどう
import cv2
import numpy as np
# read image into matrix.
m = cv2.imread("python.png")
# get image properties.
h,w,bpp = np.shape(m)
# iterate over the entire image.
for py in range(0,h):
for px in range(0,w):
m[py][px][0] = 0 //setting channel Blue to values of 0
# display image
cv2.imshow('matrix', m)
cv2.waitKey(0)
誰もが知っているのですか?私はもう何をすべきかわからない、私は立ち往生している、誰かが私を助けたら本当に感謝するだろう。
P.D. MatLabでは魅力的に機能しますが、私はPythonでそれを行うことができません。
コードゼロにRGB負の値を操作します...それらの部分を行い、それらを再度マージします。 [Here](http://docs.opencv.org/3.0-beta/doc/py_tutorials/py_core/py_basic_ops/py_basic_ops.html#splitting-and-merging-image-channels)は、分割またはマージする方法です。しかし、diff = brのように好きなだけお互いを差し引いてから、 – api55
私に返信していただきありがとうございます。実際にはイメージをフォルダに保存していました。 img.showは何らかの理由で動作しません。ありがとう。 –