###前提・実現したいこと
画像を読み込みモザイク処理を施し、保存するプログラムを作りたいです。
###発生している問題・エラーメッセージ
実行コマンド python exer5.py img.png 10 e.png エラー Traceback (most recent call last): File "exer5.py", line 35, in <module> img[y,x,2] = img[y,x,rectR(R*R)] TypeError: 'numpy.ndarray' object is not callable ###該当のソースコード
# -*- coding: utf-8 -*- # exer5.py # モザイク画像の作成 # 第2引数はモザイクのサイズ import numpy as np import sys import cv2 fname_in = sys.argv[1] R = int(sys.argv[2]) fname_out = sys.argv[3] #画像をロードしfloat型へ img = cv2.imread(fname_in) img = np.float64(img) #モザイク画像の作成 #以下を編集(for文の範囲などは適宜変更すること) for y in range( int( img.shape[0] / R + 1) ) : for x in range( int( img.shape[1] / R + 1) ) : #ヒント:スライス表現により画像の矩形領域を取り出せる rectR=0 rectG=0 rectB=0 # 以下は,[y*R, (y+1)*R) x [y*R, (y+1)*R) の矩形領域のrチャンネル rectR+= img[y*R:(y+1)*R, x*R:(x+1)*R, 2] rectG+= img[y*R:(y+1)*R, x*R:(x+1)*R, 1] rectB+= img[y*R:(y+1)*R, x*R:(x+1)*R, 0] img[y,x,2] = img[y,x,rectR(R*R)] img[y,x,1] = img[y,x,rectG(R*R)] img[y,x,0] = img[y,x,rectB(R*R)] cv2.imwrite(fname_out, np.uint8( img) ) ```###試したこと for文の中を自分で手を加えました。 頭が混乱してしまい、よく分からなくなってしまったのですがこれはアルゴリズムとしてどこを改良すべきなのでしょうか ###補足情報(言語/FW/ツール等のバージョンなど) 個人的には img[y,x,2] = img[y,x,rectR(R*R)] img[y,x,1] = img[y,x,rectG(R*R)] img[y,x,0] = img[y,x,rectB(R*R)] のためのfor文を作るべかなのかと考えていますが分けわかんなくなってしまいました。 すいません、よろしくお願いします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/12/25 05:31