Exemplo n.º 1
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))
Exemplo n.º 2
0
    def _calculate_spacing(self, im):
        h, w, d = im.shape
        #         cw, ch = 600, 600
        cw, ch = 300, 300
        cx = (w - cw) / 2
        cy = (h - ch) / 2
        im = crop(im, cx, cy, cw, ch)
        #         d = self.test_image.plotdata.get_data('imagedata000')
        d = grayspace(im)
        #         d /= 255.
        #         edges = filter.canny(d, sigma=3,
        # #                              low_threshold=0,
        # #                              high_threshold=
        #                              )
        #         edges = edges.astype('uint8')
        #         edges = vsobel(d)
        edges = sobel(d)

        nim = zeros_like(edges)
        nim[edges > 0.1] = 255
        edges = nim
        self.test_image.set_image(edges)

        hspace, angles, dists = hough_line(edges)

        self.test_image.set_image(hspace, 1)

        _hspace, angles, dists = hough_peaks(
            hspace,
            angles,
            dists,
        )
        nim = zeros_like(edges)
        h, w, d = im.shape
        xs = []

        for ti, di in zip(angles, dists):
            ai = math.degrees(ti) + 180
            di = abs(int(round(di)))
            aa = abs(ai - 90) < 1
            bb = abs(ai - 270) < 1
            if aa or bb:
                adi = abs(di)
                coords = line(0, adi, h - 1, adi)
                nim[coords] = 200
                xs.append(di)

        self.test_image.set_image(nim, 2)
        xs.sort()
        # compute difference between each pair
        dxs = diff(xs)
        print dxs
        dd = sorted(dxs)[1:]
        print dd
        while len(dd):
            if std(dd) < 3:
                print dd
                return mean(dd) * 4  # each bar =0.25mm
            else:
                dd = dd[:-1]
Exemplo n.º 3
0
    def _calculate_spacing(self, im):
        h, w, d = im.shape
#         cw, ch = 600, 600
        cw, ch = 300, 300
        cx = (w - cw) / 2
        cy = (h - ch) / 2
        im = crop(im, cx, cy, cw, ch)
#         d = self.test_image.plotdata.get_data('imagedata000')
        d = grayspace(im)
#         d /= 255.
#         edges = filter.canny(d, sigma=3,
# #                              low_threshold=0,
# #                              high_threshold=
#                              )
#         edges = edges.astype('uint8')
#         edges = vsobel(d)
        edges = sobel(d)

        nim = zeros_like(edges)
        nim[edges > 0.1] = 255
        edges = nim
        self.test_image.set_image(edges)


        hspace, angles, dists = hough_line(edges)

        self.test_image.set_image(hspace, 1)

        _hspace, angles, dists = hough_peaks(hspace, angles, dists,

                                             )
        nim = zeros_like(edges)
        h, w, d = im.shape
        xs = []

        for ti, di in zip(angles, dists):
            ai = math.degrees(ti) + 180
            di = abs(int(round(di)))
            aa = abs(ai - 90) < 1
            bb = abs(ai - 270) < 1
            if aa or bb :
                adi = abs(di)
                coords = line(0, adi, h - 1, adi)
                nim[coords] = 200
                xs.append(di)

        self.test_image.set_image(nim, 2)
        xs.sort()
        # compute difference between each pair
        dxs = diff(xs)
        print dxs
        dd = sorted(dxs)[1:]
        print dd
        while len(dd):
            if std(dd) < 3:
                print dd
                return mean(dd) * 4  # each bar =0.25mm
            else:
                dd = dd[:-1]
Exemplo n.º 4
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))
Exemplo n.º 5
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))
Exemplo n.º 6
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))
Exemplo n.º 7
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))
Exemplo n.º 8
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))
Exemplo n.º 9
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))
Exemplo n.º 10
0
    def _calculate_focus_measure(self, src, operator, roi):
        '''
            see
            IMPLEMENTATION OF A PASSIVE AUTOMATIC FOCUSING ALGORITHM
            FOR DIGITAL STILL CAMERA
            DOI 10.1109/30.468047
            and
            http://cybertron.cg.tu-berlin.de/pdci10/frankencam/#autofocus
        '''

        # need to resize to 640,480. this is the space the roi is in
#        s = resize(grayspace(pychron), 640, 480)
        src = grayspace(src)
        v = crop(src, *roi)

        di = dict(var=lambda x:variance(x),
                  laplace=lambda x: get_focus_measure(x, 'laplace'),
                  sobel=lambda x: ndsum(generic_gradient_magnitude(x, sobel, mode='nearest'))
                  )

        func = di[operator]
        return func(v)
Exemplo n.º 11
0
    def _calculate_focus_measure(self, src, operator, roi):
        '''
            see
            IMPLEMENTATION OF A PASSIVE AUTOMATIC FOCUSING ALGORITHM
            FOR DIGITAL STILL CAMERA
            DOI 10.1109/30.468047
            and
            http://cybertron.cg.tu-berlin.de/pdci10/frankencam/#autofocus
        '''

        # need to resize to 640,480. this is the space the roi is in
        #        s = resize(grayspace(pychron), 640, 480)
        src = grayspace(src)
        v = crop(src, *roi)

        di = dict(var=lambda x: variance(x),
                  laplace=lambda x: get_focus_measure(x, 'laplace'),
                  sobel=lambda x: ndsum(
                      generic_gradient_magnitude(x, sobel, mode='nearest')))

        func = di[operator]
        return func(v)