예제 #1
0
    def _draw_targets(self, src, targets, dim):
        '''
            draw a crosshairs indicator
        '''

        wh = get_size(src)
        for ta in targets:
            pt = new_point(*ta.centroid)
            self._draw_indicator(src, pt,
                                 color=(0, 255, 0),
                                 size=10,
                                 shape='crosshairs')
            draw_circle(src, pt,
                        radius=int(dim)
#                         color=color,
#                         thickness=1
                        )
#             im = zeros(wh)
#             points = asarray(ta.poly_points)
#
#             rr, cc = polygon(*points.T)
#             im[cc, rr] = 255
#
#             cx, cy = center_of_mass(im)
#             pt = new_point(cy, cx)
#             self._draw_indicator(pychron, pt,
#                                  color=(0, 255, 255),
#                                  size=10,
#                                  shape='crosshairs')
            draw_polygons(src, [ta.poly_points])
예제 #2
0
    def _crop_image(self, src, cw, ch):
        CX, CY = 0, 0
        cw_px = int(cw * self.pxpermm)
        ch_px = int(ch * self.pxpermm)
        w, h = get_size(src)

        x = int((w - cw_px) / 2 + CX)
        y = int((h - ch_px) / 2 + CY)

#        print w / self.pxpermm, cw_px / self.pxpermm
#        ra = 1
#        print self.pxpermm * ra
#        print w / float(cw)
#        self.cpxpermm = w / float(cw) / 2.
#        print h / float(ch), w / float(cw)
#        print self.pxpermm * float(w) / cw_px
#        self.cpxpermm = self.pxpermm * w / cw
#        print self.cpxpermm, w / cw
#        print w, cw_px
#        print cw, w / (cw * self.pxpermm)
#        self.croppixels = (cw_px, ch_px)
#        self.croprect = (x, y, cw_px, ch_px)
#        cw_px = ch_px = 107

        r = 4 - cw_px % 4
        cw_px = ch_px = cw_px + r

        return asarray(crop(src, x, y, cw_px, ch_px))
예제 #3
0
파일: locator.py 프로젝트: sgallet/pychron
    def _draw_targets(self, src, targets, dim):
        '''
            draw a crosshairs indicator
        '''

        wh = get_size(src)
        for ta in targets:
            pt = new_point(*ta.centroid)
            self._draw_indicator(src,
                                 pt,
                                 color=(0, 255, 0),
                                 size=10,
                                 shape='crosshairs')
            draw_circle(
                src,
                pt,
                radius=int(dim)
                #                         color=color,
                #                         thickness=1
            )
            #             im = zeros(wh)
            #             points = asarray(ta.poly_points)
            #
            #             rr, cc = polygon(*points.T)
            #             im[cc, rr] = 255
            #
            #             cx, cy = center_of_mass(im)
            #             pt = new_point(cy, cx)
            #             self._draw_indicator(pychron, pt,
            #                                  color=(0, 255, 255),
            #                                  size=10,
            #                                  shape='crosshairs')
            draw_polygons(src, [ta.poly_points])
예제 #4
0
    def _segment_polygon(self, image, frame, target,
                         dim,
                         cthreshold, mi, ma):

        src = frame[:]

        wh = get_size(src)
        # make image with polygon
        im = zeros(wh)
        points = asarray(target.poly_points)

        rr, cc = polygon(*points.T)
        im[cc, rr] = 255

        # do watershedding
        distance = ndimage.distance_transform_edt(im)
        local_maxi = feature.peak_local_max(distance, labels=im,
                                            indices=False,
#                                             footprint=ones((1, 1))
                                            )
        markers, ns = ndimage.label(local_maxi)
        wsrc = watershed(-distance, markers,
                        mask=im
                        )
        wsrc = wsrc.astype('uint8')


#         self.test_image.setup_images(3, wh)
#         self.test_image.set_image(distance, idx=0)
#         self.test_image.set_image(wsrc, idx=1)

#         self.wait()

        targets = self._find_polygon_targets(wsrc)
        ct = cthreshold * 0.75
        target = self._test_targets(wsrc, targets, ct, mi, ma)
        if not target:
            values, bins = histogram(wsrc, bins=max((10, ns)))
            # assume 0 is the most abundant pixel. ie the image is mostly background
            values, bins = values[1:], bins[1:]
            idxs = nonzero(values)[0]

            '''
                polygon is now segmented into multiple regions
                consectutively remove a region and find targets
            '''
            nimage = ones_like(wsrc, dtype='uint8') * 255
            nimage[wsrc == 0] = 0
            for idx in idxs:
                bl = bins[idx]
                bu = bins[idx + 1]
                nimage[((wsrc >= bl) & (wsrc <= bu))] = 0

                targets = self._find_polygon_targets(nimage)
                target = self._test_targets(nimage, targets, ct, mi, ma)
                if target:
                    break

        return target
예제 #5
0
    def _get_frame_center(self, src):
        """
            convenience function for geting center of image in c,r from
        """
        w, h = get_size(src)
        x = w / 2
        y = h / 2

        return x, y
예제 #6
0
파일: locator.py 프로젝트: NMGRL/pychron
    def _get_frame_center(self, src):
        """
            convenience function for geting center of image in c,r from
        """
        w, h = get_size(src)
        x = w / 2
        y = h / 2

        return x, y
예제 #7
0
파일: locator.py 프로젝트: sgallet/pychron
    def _get_frame_center(self, src):
        '''
            convenience function for geting center of image in c,r from
        '''
        w, h = get_size(src)
        x = float(w / 2)
        y = float(h / 2)

        return x, y
예제 #8
0
    def _get_frame_center(self, src):
        '''
            convenience function for geting center of image in c,r from
        '''
        w, h = get_size(src)
        x = float(w / 2)
        y = float(h / 2)

        return x, y
예제 #9
0
    def _segment_polygon(self, image, frame, target, dim, cthreshold, mi, ma):

        src = frame[:]

        wh = get_size(src)
        # make image with polygon
        im = zeros(wh)
        points = asarray(target.poly_points)

        rr, cc = polygon(*points.T)
        im[cc, rr] = 255

        # do watershedding
        distance = ndimage.distance_transform_edt(im)
        local_maxi = feature.peak_local_max(
            distance,
            labels=im,
            indices=False,
            #                                             footprint=ones((1, 1))
        )
        markers, ns = ndimage.label(local_maxi)
        wsrc = watershed(-distance, markers, mask=im)
        wsrc = wsrc.astype('uint8')

        #         self.test_image.setup_images(3, wh)
        #         self.test_image.set_image(distance, idx=0)
        #         self.test_image.set_image(wsrc, idx=1)

        #         self.wait()

        targets = self._find_polygon_targets(wsrc)
        ct = cthreshold * 0.75
        target = self._test_targets(wsrc, targets, ct, mi, ma)
        if not target:
            values, bins = histogram(wsrc, bins=max((10, ns)))
            # assume 0 is the most abundant pixel. ie the image is mostly background
            values, bins = values[1:], bins[1:]
            idxs = nonzero(values)[0]
            '''
                polygon is now segmented into multiple regions
                consectutively remove a region and find targets
            '''
            nimage = ones_like(wsrc, dtype='uint8') * 255
            nimage[wsrc == 0] = 0
            for idx in idxs:
                bl = bins[idx]
                bu = bins[idx + 1]
                nimage[((wsrc >= bl) & (wsrc <= bu))] = 0

                targets = self._find_polygon_targets(nimage)
                target = self._test_targets(nimage, targets, ct, mi, ma)
                if target:
                    break

        return target
예제 #10
0
    def crop(self, src, cw, ch, ox=0, oy=0):

        cw_px = int(cw * self.pxpermm)
        ch_px = int(ch * self.pxpermm)
        w, h = get_size(src)

        x = int((w - cw_px) / 2. + ox)
        y = int((h - ch_px) / 2. + oy)

        # r = 4 - cw_px % 4
        # cw_px = ch_px = cw_px + r

        return asarray(crop(src, x, y, cw_px, ch_px))
예제 #11
0
파일: locator.py 프로젝트: kenlchen/pychron
    def crop(self, src, cw, ch, ox=0, oy=0):

        cw_px = int(cw * self.pxpermm)
        ch_px = int(ch * self.pxpermm)
        w, h = get_size(src)

        x = int((w - cw_px) / 2. + ox)
        y = int((h - ch_px) / 2. + oy)

        # r = 4 - cw_px % 4
        # cw_px = ch_px = cw_px + r

        return asarray(crop(src, x, y, cw_px, ch_px))
예제 #12
0
    def _crop_image(self, src):
        ccx, ccy = 0, 0
        cw_px, ch_px = self.get_frame_size()
        # cw_px = int(cw)# * self.pxpermm)
        # ch_px = int(ch)# * self.pxpermm)
        w, h = get_size(src)

        x = int((w - cw_px) / 2 + ccx)
        y = int((h - ch_px) / 2 + ccy)

        r = 4 - cw_px % 4
        cw_px += r

        return asarray(crop(src, x, y, cw_px, cw_px))
예제 #13
0
    def _crop_image(self, src):
        ccx, ccy = 0, 0
        cw_px, ch_px = self.get_frame_size()
        # cw_px = int(cw)# * self.pxpermm)
        # ch_px = int(ch)# * self.pxpermm)
        w, h = get_size(src)

        x = int((w - cw_px) / 2 + ccx)
        y = int((h - ch_px) / 2 + ccy)

        r = 4 - cw_px % 4
        cw_px += r

        return asarray(crop(src, x, y, cw_px, cw_px))
예제 #14
0
파일: locator.py 프로젝트: NMGRL/pychron
    def crop(self, src, cw, ch, ox=0, oy=0, verbose=True):

        cw_px = int(cw * self.pxpermm)
        ch_px = int(ch * self.pxpermm)
        w, h = get_size(src)

        x = int((w - cw_px) / 2. + ox)
        y = int((h - ch_px) / 2. - oy)

        # r = 4 - cw_px % 4
        # cw_px = ch_px = cw_px + r
        if verbose:
            self.debug('Crop: x={},y={}, cw={}, ch={}, '
                       'width={}, height={}, ox={}, oy={}'.format(x, y, cw_px, ch_px, w, h, ox, oy))
        return asarray(crop(src, x, y, cw_px, ch_px))
예제 #15
0
    def crop(self, src, cw, ch, ox=0, oy=0, verbose=True):

        cw_px = int(cw * self.pxpermm)
        ch_px = int(ch * self.pxpermm)
        w, h = get_size(src)

        x = int((w - cw_px) / 2. + ox)
        y = int((h - ch_px) / 2. - oy)

        # r = 4 - cw_px % 4
        # cw_px = ch_px = cw_px + r
        if verbose:
            self.debug('Crop: x={},y={}, cw={}, ch={}, '
                       'width={}, height={}, ox={}, oy={}'.format(
                           x, y, cw_px, ch_px, w, h, ox, oy))
        return asarray(crop(src, x, y, cw_px, ch_px))