質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
NumPy

NumPyはPythonのプログラミング言語の科学的と数学的なコンピューティングに関する拡張モジュールです。

OpenCV

OpenCV(オープンソースコンピュータービジョン)は、1999年にインテルが開発・公開したオープンソースのコンピュータビジョン向けのクロスプラットフォームライブラリです。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

解決済

1回答

1679閲覧

pythonでマスク処理した画像を3次元にする方法

trafalbad

総合スコア303

NumPy

NumPyはPythonのプログラミング言語の科学的と数学的なコンピューティングに関する拡張モジュールです。

OpenCV

OpenCV(オープンソースコンピュータービジョン)は、1999年にインテルが開発・公開したオープンソースのコンピュータビジョン向けのクロスプラットフォームライブラリです。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2019/05/25 14:03

編集2019/05/25 15:50

下のように画像をマスク処理しました

python

1import cv2 2im=dataset.load_image(1) 3 4im_gray = 0.299 * im[:, :, 0] + 0.587 * im[:, :, 1] + 0.114 * im[:, :, 2] 5 6print(im.dtype) 7print(im_gray.dtype) 8# uint8 9# float64 10 11print(im.shape) 12print(im_gray.shape) 13# (512, 512, 3) 14# (512, 512)

このマスク処理した画像に整数のラベル番号を加え、3次元にする方法はないでしょうか?
label番号=51
だとすると**shape=(512, 512)の画像に加えてshape=(512, 512, 51)**としたいのですが。ご教授お願いします

python

1# このようにしたい 2 3label=51 4print(add_label_img.shape) 5# (512, 512, 3)

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

hayataka2049

2019/05/25 21:45

shape=(512, 512, 51)にしたとして、この配列の中身はどうなっているのでしょうか。
guest

回答1

0

自己解決

python

1def load_mask(self, image_id): 2 """Load instance masks for the given image. 3 Different datasets use different ways to store masks. This 4 function converts the different mask format to one format 5 in the form of a bitmap [height, width, instances]. 6 Returns: 7 masks: A bool array of shape [height, width, instance count] with 8 one mask per instance. 9 class_ids: a 1D array of class IDs of the instance masks. 10 """ 11 # If not a COCO image, delegate to parent class. 12 image_info = self.image_info[image_id] 13 if image_info["source"] != "coco": 14 return super(CocoDataset, self).load_mask(image_id) 15 16 instance_masks = [] 17 class_ids = [] 18 annotations = self.image_info[image_id]["annotations"] 19 # Build mask of shape [height, width, instance_count] and list 20 # of class IDs that correspond to each channel of the mask. 21 for annotation in annotations: 22 class_id = self.map_source_class_id( 23 "coco.{}".format(annotation['category_id'])) 24 if class_id: 25 m = self.annToMask(annotation, image_info["height"], 26 image_info["width"]) 27 # Some objects are so small that they're less than 1 pixel area 28 # and end up rounded out. Skip those objects. 29 if m.max() < 1: 30 continue 31 # Is it a crowd? If so, use a negative class ID. 32 if annotation['iscrowd']: 33 # Use negative class ID for crowds 34 class_id *= -1 35 # For crowd masks, annToMask() sometimes returns a mask 36 # smaller than the given dimensions. If so, resize it. 37 if m.shape[0] != image_info["height"] or m.shape[1] != image_info["width"]: 38 m = np.ones([image_info["height"], image_info["width"]], dtype=bool) 39 instance_masks.append(m) 40 class_ids.append(class_id) 41 42 # Pack instance masks into an array 43 if class_ids: 44 mask = np.stack(instance_masks, axis=2).astype(np.bool) 45 class_ids = np.array(class_ids, dtype=np.int32) 46 return mask, class_ids 47 else: 48 # Call super class to return an empty mask 49 return super(CocoDataset, self).load_mask(image_id)

投稿2019/05/26 03:21

trafalbad

総合スコア303

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問