numpyを使用して次の画像を分割して丸を一つ一つにわけて保存したいです。
こちらの記事を参考にコードを書きました。
行方向に4分割しようと思い、以下のコードを書きました。
python
1v_size = img.shape[0] // 4 * 4 2h_size = img.shape[1] 3img = img[:v_size, :h_size] 4 5v_split = img.shape[0] // 4 6out_img = [] 7out_img.extend(np.vsplit(img,v_split )) 8 9plt.imshow(img) 10plt.show()
結果
その結果最後の行と列だけなくなってしまいました。
コードの間違っている点と、参考にした記事のように分割して保存する方法を知りたいです。
↓行・列での分割は以下のようです。
回答よろしくお願いします。
python
1v_size = img.shape[0] // size * size 2h_size = img.shape[1] // size * size 3img = img[:v_size, :h_size] 4 5v_split = img.shape[0] // size 6h_split = img.shape[1] // size 7out_img = [] 8[out_img.extend(np.hsplit(h_img, h_split)) 9 for h_img in np.vsplit(img, v_split)]
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/09/13 07:07