コード例 #1
0
def obsolete_test_center_zoom_even(imsize,outsize,cx,cy,upsample_factor,doplot=False):
    if imsize != outsize and np.abs(imsize-outsize)==1:
        return "Yarrr, something's awry!"
    pixspace = np.mean(np.diff(np.linspace(-5,5,imsize)))
    image = gaussian(imsize)

    image_shifted = gaussian(imsize,cx*pixspace,cy*pixspace)
    zoom_pixspace = np.mean(np.diff(np.linspace(-5/float(upsample_factor),5/float(upsample_factor),imsize)))
    image_shifted_zoomed = zoomed_gaussian(imsize,outsize,cx*zoom_pixspace, cy*zoom_pixspace,upsample_factor)
    image_zoomed = zoomed_gaussian(imsize,outsize, 0, 0, upsample_factor)
    #image_shifted_zoomed = zoomed_gaussian(outsize,pixspace/2,pixspace/2,upsample_factor)

    middle = np.unravel_index(image.argmax(),image.shape)
    ismax = np.unravel_index(image_shifted.argmax(),image.shape)
    assert (ismax[0]-middle[0]) == cy
    assert (ismax[1]-middle[1]) == cx

    dmax = np.unravel_index(image_shifted_zoomed.argmax(),image.shape)
    x,y,zoom = upsample.center_zoom_image(image_shifted, upsample_factor=upsample_factor, output_size=outsize, nthreads=4,
            xshift=cx, yshift=cy, return_axes=True)

    zmax = np.unravel_index(zoom.argmax(),zoom.shape)
    #print 'image position of max:',dmax,' zoom position of max:',zmax
    #print 'x,y max: ',x[zmax],y[zmax]
    clf()

    vshape = image.shape[0]*upsample_factor,image.shape[1]*upsample_factor
    s1,s2 = outsize,outsize
    roff = -int(np.round(float(vshape[0] - upsample_factor - s1)/2)) - (upsample_factor%2==0)
    coff = -int(np.round(float(vshape[1] - upsample_factor - s2)/2)) - (upsample_factor%2==0)

    if doplot:
        if imsize * upsample_factor < 512:
            fx,fy,fullzoom = upsample.center_zoom_image(image, xshift=cx, yshift=cy, upsample_factor=upsample_factor, nthreads=4, return_axes=True)
        else:
            fullzoom = None
        if image.shape == zoom.shape:
            plotthings(image,image_shifted,image_zoomed,zoom,cx,cy,upsample_factor,imsize,outsize,x,y,fullzoom=fullzoom)
        else:
            plotthings(image,image_shifted,image_zoomed[:image.shape[0],:image.shape[1]],zoom[:image.shape[0],:image.shape[1]],       cx,cy,upsample_factor,imsize,outsize,x[:image.shape[0],:image.shape[1]],y[:image.shape[0],:image.shape[1]],fullzoom=fullzoom)

    print " ".join(["%6.2f" % q for q in 
        (upsample_factor,imsize,outsize,cx,cy,x[zmax],y[zmax],zmax[1],zmax[0],dmax[1],dmax[0],x[zmax]-dmax[1],y[zmax]-dmax[0],
            cx/float(upsample_factor),cy/float(upsample_factor),((zoom-image_zoomed)**2).sum(),
            ismax[0]-middle[0],ismax[1]-middle[1])])

    zmax = np.where(np.abs(zoom-zoom.max()) < 1e-8)
    #assert np.round(np.mean(y[zmax])) == floor(image.shape[0]/2.+cy)
    #assert np.round(np.mean(x[zmax])) == floor(image.shape[1]/2.+cx)


    #assert (x[zmax]) == dmax[1]
    #assert (y[zmax]) == dmax[0]
    #if upsample_factor == 1 and image.shape==zoom.shape:
    #    assert dmax[0] == zmax[0]
    #    assert dmax[1] == zmax[1]
    assert ((zoom-image_zoomed)**2).sum() < 0.001
コード例 #2
0
def obsolete_test_center_zoom_even(imsize,outsize,cx,cy,upsample_factor,doplot=False):
    if imsize != outsize and np.abs(imsize-outsize)==1:
        return "Yarrr, something's awry!"
    pixspace = np.mean(np.diff(np.linspace(-5,5,imsize)))
    image = gaussian(imsize)

    image_shifted = gaussian(imsize,cx*pixspace,cy*pixspace)
    zoom_pixspace = np.mean(np.diff(np.linspace(-5/float(upsample_factor),5/float(upsample_factor),imsize)))
    image_shifted_zoomed = zoomed_gaussian(imsize,outsize,cx*zoom_pixspace, cy*zoom_pixspace,upsample_factor)
    image_zoomed = zoomed_gaussian(imsize,outsize, 0, 0, upsample_factor)
    #image_shifted_zoomed = zoomed_gaussian(outsize,pixspace/2,pixspace/2,upsample_factor)

    middle = np.unravel_index(image.argmax(),image.shape)
    ismax = np.unravel_index(image_shifted.argmax(),image.shape)
    assert (ismax[0]-middle[0]) == cy
    assert (ismax[1]-middle[1]) == cx

    dmax = np.unravel_index(image_shifted_zoomed.argmax(),image.shape)
    x,y,zoom = upsample.center_zoom_image(image_shifted, upsample_factor=upsample_factor, output_size=outsize, nthreads=4,
            xshift=cx, yshift=cy, return_axes=True)

    zmax = np.unravel_index(zoom.argmax(),zoom.shape)
    #print 'image position of max:',dmax,' zoom position of max:',zmax
    #print 'x,y max: ',x[zmax],y[zmax]
    clf()

    vshape = image.shape[0]*upsample_factor,image.shape[1]*upsample_factor
    s1,s2 = outsize,outsize
    roff = -int(np.round(float(vshape[0] - upsample_factor - s1)/2)) - (upsample_factor%2==0)
    coff = -int(np.round(float(vshape[1] - upsample_factor - s2)/2)) - (upsample_factor%2==0)

    if doplot:
        if imsize * upsample_factor < 512:
            fx,fy,fullzoom = upsample.center_zoom_image(image, xshift=cx, yshift=cy, upsample_factor=upsample_factor, nthreads=4, return_axes=True)
        else:
            fullzoom = None
        if image.shape == zoom.shape:
            plotthings(image,image_shifted,image_zoomed,zoom,cx,cy,upsample_factor,imsize,outsize,x,y,fullzoom=fullzoom)
        else:
            plotthings(image,image_shifted,image_zoomed[:image.shape[0],:image.shape[1]],zoom[:image.shape[0],:image.shape[1]],       cx,cy,upsample_factor,imsize,outsize,x[:image.shape[0],:image.shape[1]],y[:image.shape[0],:image.shape[1]],fullzoom=fullzoom)

    print " ".join(["%6.2f" % q for q in 
        (upsample_factor,imsize,outsize,cx,cy,x[zmax],y[zmax],zmax[1],zmax[0],dmax[1],dmax[0],x[zmax]-dmax[1],y[zmax]-dmax[0],
            cx/float(upsample_factor),cy/float(upsample_factor),((zoom-image_zoomed)**2).sum(),
            ismax[0]-middle[0],ismax[1]-middle[1])])

    zmax = np.where(np.abs(zoom-zoom.max()) < 1e-8)
    #assert np.round(np.mean(y[zmax])) == floor(image.shape[0]/2.+cy)
    #assert np.round(np.mean(x[zmax])) == floor(image.shape[1]/2.+cx)


    #assert (x[zmax]) == dmax[1]
    #assert (y[zmax]) == dmax[0]
    #if upsample_factor == 1 and image.shape==zoom.shape:
    #    assert dmax[0] == zmax[0]
    #    assert dmax[1] == zmax[1]
    assert ((zoom-image_zoomed)**2).sum() < 0.001
コード例 #3
0
def obsolete_test_center_zoom_simple3(imsize,upsample_factor,doplot=False):
    image = gaussian(imsize)

    x,y,zoom = upsample.center_zoom_image(image,
            upsample_factor=upsample_factor, output_size=image.shape,
            nthreads=4, return_axes=True)

    if imsize * upsample_factor < 512:
        fx,fy,fullzoom = upsample.center_zoom_image(image,
                upsample_factor=upsample_factor, nthreads=4, return_axes=True)
    else:
        fullzoom = None

    if doplot:
        plotthings(image,image,image,zoom,0,0,upsample_factor,imsize,imsize,x,y,fullzoom=fullzoom)

    # in order for zooming to work, need to at least nyquist-sample peak
    # (I think)
    if imsize > 10:
        assert ((image-zoom)**2).sum() < 0.001
コード例 #4
0
def obsolete_test_center_zoom_simple3(imsize,upsample_factor,doplot=False):
    image = gaussian(imsize)

    x,y,zoom = upsample.center_zoom_image(image,
            upsample_factor=upsample_factor, output_size=image.shape,
            nthreads=4, return_axes=True)

    if imsize * upsample_factor < 512:
        fx,fy,fullzoom = upsample.center_zoom_image(image,
                upsample_factor=upsample_factor, nthreads=4, return_axes=True)
    else:
        fullzoom = None

    if doplot:
        plotthings(image,image,image,zoom,0,0,upsample_factor,imsize,imsize,x,y,fullzoom=fullzoom)

    # in order for zooming to work, need to at least nyquist-sample peak
    # (I think)
    if imsize > 10:
        assert ((image-zoom)**2).sum() < 0.001