私のニーズに合わせて既存のコードをカスタマイズしようとしています。もともと、コードはimgs = np.ndarray((total, 1, image_rows, image_cols), dtype=np.uint8)
を使用して、画像ファイルのリストをnumpy配列形式で保存します。フォルダを反復すると、各画像ファイルは次のように読み取られます。img = skimage.io.imread(os.path.join(train_data_path, image_name))
正常に動作します。次のように コードは次のとおりです。入力画像から得られるnumpy配列の形状を変更する場合
image_rows = 420
image_cols = 580
imgs = np.ndarray((total, 1, image_rows, image_cols), dtype=np.uint8)
i=0
for image_name in images:
img = skimage.io.imread(os.path.join(train_data_path, image_name))
img = np.array([img])
imgs[i]=img
i+=1
自分のニーズに合うために、私は、形状[total, image_rows,image_cols,1]
の画像ファイル配列を有する傾向があります。言い換えれば、私はしかし、コードを実行すると、次のエラー
imgs[i] = img
ValueError: could not broadcast input array from shape (1,420,580) into shape
(420,580,1)
を起こしimgs = np.ndarray((total,image_rows, image_cols,1), dtype=np.uint8)
として、それを変更し、元々のファイルから読み込んだ後[1,420,580]
の形状をしているimg
の形状を変更するにはどのような方法があります。どのように画像の対応するピクセル値に影響を与えずに[420,580,1]
に変更できますか?
おかげで、仕事をimg.reshapeます。私はまた形を変えた。コードがコンパイルできるように見えます。私の唯一の問題は、[1,420,580]のピクセルがピクセル[420,580,1]と正確に一致することを保証することができるということです。 – user288609