Hướng dẫn how do you merge two masks in python? - làm thế nào để bạn hợp nhất hai mặt nạ trong python?
Tôi muốn làm điều gì đó như thế này: Show
Lưu ý, ví dụ này dẫn đến một lỗi
Jaime 63,9K17 Huy hiệu vàng120 Huy hiệu bạc158 Huy hiệu đồng17 gold badges120 silver badges158 bronze badges Đã hỏi ngày 22 tháng 3 năm 2013 lúc 20:24Mar 22, 2013 at 20:24
1 Bạn đang sử dụng danh sách Python thay vì các mảng Numpy. Thay vào đó hãy thử điều này:
Trong ví dụ của bạn, khi 8 là một danh sách, 9 được đánh giá là >>> m1 = np.ma.make_mask([0, 1, 1, 0]) >>> m2 = np.ma.make_mask([1, 0, 0, 0]) >>> np.ma.mask_or(m1, m2) array([ True, True, True, False])0 (giống nhau đối với >>> m1 = np.ma.make_mask([0, 1, 1, 0]) >>> m2 = np.ma.make_mask([1, 0, 0, 0]) >>> np.ma.mask_or(m1, m2) array([ True, True, True, False])1), vì vậy mặt nạ là >>> m1 = np.ma.make_mask([0, 1, 1, 0]) >>> m2 = np.ma.make_mask([1, 0, 0, 0]) >>> np.ma.mask_or(m1, m2) array([ True, True, True, False])0 và >>> m1 = np.ma.make_mask([0, 1, 1, 0]) >>> m2 = np.ma.make_mask([1, 0, 0, 0]) >>> np.ma.mask_or(m1, m2) array([ True, True, True, False])3. Đã trả lời ngày 22 tháng 3 năm 2013 lúc 20:27Mar 22, 2013 at 20:27
Tiagotiagotiago 21.8K11 Huy hiệu vàng71 Huy hiệu bạc86 Huy hiệu đồng11 gold badges71 silver badges86 bronze badges 6 Kết hợp hai mặt nạ với toán tử >>> m1 = np.ma.make_mask([0, 1, 1, 0]) >>> m2 = np.ma.make_mask([1, 0, 0, 0]) >>> np.ma.mask_or(m1, m2) array([ True, True, True, False])4. Kết quả có thể là chế độ xem trên M1 hoặc M2 nếu cái kia là >>> m1 = np.ma.make_mask([0, 1, 1, 0]) >>> m2 = np.ma.make_mask([1, 0, 0, 0]) >>> np.ma.mask_or(m1, m2) array([ True, True, True, False])5 (tức là sai).Tham số1, m2array_likem1, m2array_like Mặt nạ đầu vào. Copybool, tùy chọnbool, optionalNếu bản sao là sai và một trong các đầu vào là >>> m1 = np.ma.make_mask([0, 1, 1, 0]) >>> m2 = np.ma.make_mask([1, 0, 0, 0]) >>> np.ma.mask_or(m1, m2) array([ True, True, True, False])5, hãy trả về chế độ xem mặt nạ đầu vào khác. Mặc định là sai.co lại, tùy chọnbool, optional Có nên thu nhỏ đầu ra xuống >>> m1 = np.ma.make_mask([0, 1, 1, 0]) >>> m2 = np.ma.make_mask([1, 0, 0, 0]) >>> np.ma.mask_or(m1, m2) array([ True, True, True, False])5 nếu tất cả các giá trị của nó là sai. Mặc định là đúng.ReturnSmaskOutput Maskmaskoutput mask Các giá trị mặt nạ kết quả được che trong M1 hoặc M2. RAISEVALUEERRORNếu M1 và M2 có các DTYpes linh hoạt khác nhau. Ví dụ >>> m1 = np.ma.make_mask([0, 1, 1, 0]) >>> m2 = np.ma.make_mask([1, 0, 0, 0]) >>> np.ma.mask_or(m1, m2) array([ True, True, True, False]) Sau đây là 24 ví dụ mã của mặt nạ.merge (). Bạn có thể bỏ phiếu cho những người bạn thích hoặc bỏ phiếu cho những người bạn không thích và đi đến dự án gốc hoặc tệp nguồn bằng cách theo các liên kết trên mỗi ví dụ. Bạn cũng có thể muốn kiểm tra tất cả các chức năng/lớp có sẵn của mặt nạ mô -đun hoặc thử chức năng tìm kiếm.24 code examples of mask.merge(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module mask, or try the search function .Ví dụ 1 def annToRLE(self, ann): """ Convert annotation which can be polygons, uncompressed RLE to RLE. :return: binary mask (numpy 2D array) """ t = self.imgs[ann['image_id']] h, w = t['height'], t['width'] segm = ann['segmentation'] if type(segm) == list: # polygon -- a single object might consist of multiple parts # we merge all parts into one mask rle code rles = mask.frPyObjects(segm, h, w) rle = mask.merge(rles) elif type(segm['counts']) == list: # uncompressed RLE rle = mask.frPyObjects(segm, h, w) else: # rle rle = ann['segmentation'] return rle Ví dụ #2 def annToRLE(self, ann): """ Convert annotation which can be polygons, uncompressed RLE to RLE. :return: binary mask (numpy 2D array) """ t = self.imgs[ann['image_id']] h, w = t['height'], t['width'] segm = ann['segmentation'] if type(segm) == list: # polygon -- a single object might consist of multiple parts # we merge all parts into one mask rle code rles = mask.frPyObjects(segm, h, w) rle = mask.merge(rles) elif type(segm['counts']) == list: # uncompressed RLE rle = mask.frPyObjects(segm, h, w) else: # rle rle = ann['segmentation'] return rle Ví dụ #3 def annToRLE(self, ann): """ Convert annotation which can be polygons, uncompressed RLE to RLE. :return: binary mask (numpy 2D array) """ t = self.imgs[ann['image_id']] h, w = t['height'], t['width'] segm = ann['segmentation'] if type(segm) == list: # polygon -- a single object might consist of multiple parts # we merge all parts into one mask rle code rles = mask.frPyObjects(segm, h, w) rle = mask.merge(rles) elif type(segm['counts']) == list: # uncompressed RLE rle = mask.frPyObjects(segm, h, w) else: # rle rle = ann['segmentation'] return rle Ví dụ #4 def annToRLE(self, ann): """ Convert annotation which can be polygons, uncompressed RLE to RLE. :return: binary mask (numpy 2D array) """ t = self.imgs[ann['image_id']] h, w = t['height'], t['width'] segm = ann['segmentation'] if type(segm) == list: # polygon -- a single object might consist of multiple parts # we merge all parts into one mask rle code rles = mask.frPyObjects(segm, h, w) rle = mask.merge(rles) elif type(segm['counts']) == list: # uncompressed RLE rle = mask.frPyObjects(segm, h, w) else: # rle rle = ann['segmentation'] return rle Ví dụ #5 def annToRLE(self, ann): """ Convert annotation which can be polygons, uncompressed RLE to RLE. :return: binary mask (numpy 2D array) """ t = self.imgs[ann['image_id']] h, w = t['height'], t['width'] segm = ann['segmentation'] if type(segm) == list: # polygon -- a single object might consist of multiple parts # we merge all parts into one mask rle code rles = mask.frPyObjects(segm, h, w) rle = mask.merge(rles) elif type(segm['counts']) == list: # uncompressed RLE rle = mask.frPyObjects(segm, h, w) else: # rle rle = ann['segmentation'] return rle Ví dụ #6 def annToRLE(self, ann): """ Convert annotation which can be polygons, uncompressed RLE to RLE. :return: binary mask (numpy 2D array) """ t = self.imgs[ann['image_id']] h, w = t['height'], t['width'] segm = ann['segmentation'] if type(segm) == list: # polygon -- a single object might consist of multiple parts # we merge all parts into one mask rle code rles = mask.frPyObjects(segm, h, w) rle = mask.merge(rles) elif type(segm['counts']) == list: # uncompressed RLE rle = mask.frPyObjects(segm, h, w) else: # rle rle = ann['segmentation'] return rle Ví dụ #7 def annToRLE(self, ann): """ Convert annotation which can be polygons, uncompressed RLE to RLE. :return: binary mask (numpy 2D array) """ t = self.imgs[ann['image_id']] h, w = t['height'], t['width'] segm = ann['segmentation'] if type(segm) == list: # polygon -- a single object might consist of multiple parts # we merge all parts into one mask rle code rles = mask.frPyObjects(segm, h, w) rle = mask.merge(rles) elif type(segm['counts']) == list: # uncompressed RLE rle = mask.frPyObjects(segm, h, w) else: # rle rle = ann['segmentation'] return rle Ví dụ #8 def annToRLE(self, ann): """ Convert annotation which can be polygons, uncompressed RLE to RLE. :return: binary mask (numpy 2D array) """ t = self.imgs[ann['image_id']] h, w = t['height'], t['width'] segm = ann['segmentation'] if type(segm) == list: # polygon -- a single object might consist of multiple parts # we merge all parts into one mask rle code rles = mask.frPyObjects(segm, h, w) rle = mask.merge(rles) elif type(segm['counts']) == list: # uncompressed RLE rle = mask.frPyObjects(segm, h, w) else: # rle rle = ann['segmentation'] return rle Ví dụ #9 2Ví dụ #10 2Ví dụ #11 2Ví dụ #12 2Ví dụ #13 2Ví dụ #14 2Ví dụ #15 2Ví dụ #16 2Ví dụ #17 2Ví dụ #18 2Ví dụ #19 2Ví dụ #20 2Ví dụ #21 2Ví dụ #22 2Ví dụ #23 2Ví dụ #24 2
Làm cách nào để hợp nhất hai mặt nạ trong opencv?Chỉ cần thêm chúng và clip trong OpenCV CV.Thêm (Mask1, Mask2, ... Maskn) ... Đọc mặt nạ và chuyển đổi thành Float trong phạm vi 0 đến 1 .. Thêm mặt nạ bằng cách bổ sung Python và nhân với 255 .. Kẹp mặt nạ kết quả vào phạm vi 0 đến 255 và chuyển đổi trở lại Int .. Làm thế nào để bạn áp dụng mặt nạ mảng trong Python?Sử dụng hàm Masked_where (): Truyền hai mảng trong hàm dưới dạng tham số sau đó sử dụng Numpy.MA.Chức năng Masked_where () trong đó vượt qua điều kiện để che giấu và mảng để được che dấu..... Sử dụng hàm nasked_where (), getmask () và masked_array (): Truyền hai mảng trong hàm dưới dạng tham số sau đó sử dụng Numpy.MA .. |