0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

グラフのグレースケール化

Posted at

色付き散布図のグレースケール化

要素によって青から赤にグラデーションしている散布図をモノクロ印刷すると青と赤は薄い灰色、中央は濃い灰色になり、意図した散布図ではなくなってしまった

青色を赤色に置きかえ

青を含む色をもっている場合、そのピクセルの赤と同値になるようにする。
そうすると、赤主体になり青の成分は表に出にくくなる

import cv2  # OpenCVのインポート
import numpy as np  # numpyのインポート
img = cv2.imread('graph_a.png') # 画像の読み出し
img_2 = np.copy(img)
img_2[:, :, 0] = np.where((img[:, :, 0] != img[:, :, 1])|(img[:, :, 1] != img[:, :, 2]),img[:, :, 2],img[:, :, 0])	#グレースケールではないピクセルをみつけたら、Bの値をRに置き換え
gray = cv2.cvtColor(img_2, cv2.COLOR_BGR2GRAY) # グレースケール変換
cv2.imwrite('graph_a_conv.png',gray) # 画像の保存 

もっと賢いやりかたがある気がする

元データから作り直すことができればベストだけど、今回は散布図画像しか入手できなかったのでこれで…

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?