| 577 | |
| 578 | |
| 579 | class _ClassUniform(object): |
| 580 | def __init__(self, size, crop_nopad, scale_min=0.5, scale_max=2.0, ignore_index=0, |
| 581 | class_list=[16, 15, 14]): |
| 582 | """ |
| 583 | This is the initialization for class uniform sampling |
| 584 | :param size: crop size (int) |
| 585 | :param crop_nopad: Padding or no padding (bool) |
| 586 | :param scale_min: Minimum Scale (float) |
| 587 | :param scale_max: Maximum Scale (float) |
| 588 | :param ignore_index: The index value to ignore in the GT images (unsigned int) |
| 589 | :param class_list: A list of class to sample around, by default Truck, train, bus |
| 590 | """ |
| 591 | self.size = size |
| 592 | self.crop = RandomCrop(self.size, ignore_index=ignore_index, nopad=crop_nopad) |
| 593 | |
| 594 | self.class_list = class_list.replace(" ", "").split(",") |
| 595 | |
| 596 | self.scale_min = scale_min |
| 597 | self.scale_max = scale_max |
| 598 | |
| 599 | def detect_peaks(self, image): |
| 600 | """ |
| 601 | Takes an image and detect the peaks usingthe local maximum filter. |
| 602 | Returns a boolean mask of the peaks (i.e. 1 when |
| 603 | the pixel's value is the neighborhood maximum, 0 otherwise) |
| 604 | |
| 605 | :param image: An 2d input images |
| 606 | :return: Binary output images of the same size as input with pixel value equal |
| 607 | to 1 indicating that there is peak at that point |
| 608 | """ |
| 609 | |
| 610 | # define an 8-connected neighborhood |
| 611 | neighborhood = generate_binary_structure(2, 2) |
| 612 | |
| 613 | # apply the local maximum filter; all pixel of maximal value |
| 614 | # in their neighborhood are set to 1 |
| 615 | local_max = maximum_filter(image, footprint=neighborhood) == image |
| 616 | # local_max is a mask that contains the peaks we are |
| 617 | # looking for, but also the background. |
| 618 | # In order to isolate the peaks we must remove the background from the mask. |
| 619 | |
| 620 | # we create the mask of the background |
| 621 | background = (image == 0) |
| 622 | |
| 623 | # a little technicality: we must erode the background in order to |
| 624 | # successfully subtract it form local_max, otherwise a line will |
| 625 | # appear along the background border (artifact of the local maximum filter) |
| 626 | eroded_background = binary_erosion(background, structure=neighborhood, |
| 627 | border_value=1) |
| 628 | |
| 629 | # we obtain the final mask, containing only peaks, |
| 630 | # by removing the background from the local_max mask (xor operation) |
| 631 | detected_peaks = local_max ^ eroded_background |
| 632 | |
| 633 | return detected_peaks |
| 634 | |
| 635 | def __call__(self, img, mask): |
| 636 | """ |
nothing calls this directly
no outgoing calls
no test coverage detected