def loadFloatProcessor(filepath, params, scale=True):
    try:
        fp = loadImp(filepath).getProcessor().convertToFloatProcessor()
        # Preprocess images: Gaussian-blur to scale down, then normalize contrast
        if scale:
            fp = Filter.createDownsampled(fp, params["scale"], 0.5, 1.6)
            Util.normalizeContrast(fp)
        return fp
    except:
        syncPrint(sys.exc_info())
def loadFloatProcessor(filepath, params, paramsSIFT, scale=True):
    try:
        fp = loadImp(filepath).getProcessor().convertToFloatProcessor()
        # Preprocess images: Gaussian-blur to scale down, then normalize contrast
        if scale:
            fp = Filter.createDownsampled(fp, params["scale"], 0.5,
                                          paramsSIFT.initialSigma)
            Util.normalizeContrast(fp)  # TODO should be outside the if clause?
        return fp
    except:
        syncPrintQ(sys.exc_info())
    options2.multiplierEstimationIterations = 10
    options2.coordinateUpdateRegularizerWeight = 0.1

    if not doXYScale:
        xyScale = 1.0
    
   

    img = imgSource.clone()
    print stackSource.getSize()
    if doXYScale:
        stack = ImageStack(int(round(imgSource.getWidth()*xyScale)), int(round(imgSource.getHeight()*xyScale)))
        for z in xrange(stackSource.getSize()):
            stack.addSlice(Filter.createDownsampled(
                stackSource.getProcessor(z+1),
    	        xyScale,
    	        0.5,
                0.5))
                
             
        img = ImagePlus("", stack)
    else:
        img = imgSource

    width  = img.getWidth()
    height =  img.getHeight()

    # img.show()
    print img.getWidth(), img.getHeight(), img.getStack().getSize()
    for c in correlationRanges:    
        correlationRange = c
            
            tilesAtMatch = tilesAt[match[0]]
            bb = match[1].getBounds()

            # maybe set floatp=False for all of these
            ip1a = MapTransform.doMap(patch, bb, interpolate=True, floatp=False)
            ip1b = MapTransform.doMap(overlays[patch], bb)
            ip2a = MapTransform.doMap(match[0], bb, interpolate=True, floatp=False)
            ip2b = MapTransform.doMap(overlays[match[0]], bb)

            # show images for debugging purposes
            # ImagePlus("", ip1a).show()
            # ImagePlus("", ip2a).show()
            
            imp1a = ImagePlus("%s" % patch, Filter.scale(ip1a, scaleFactor))
            imp1b = ImagePlus("%s" % overlays[patch], ip1b.resize(Math.round( scaleFactor*ip1b.getWidth() ), Math.round( scaleFactor*ip1b.getHeight() ) ) )
            imp2a = ImagePlus("%s" % match[0], Filter.scale(ip2a, scaleFactor))
            imp2b = ImagePlus("%s" % overlays[match[0]], ip2b.resize(Math.round( scaleFactor*ip2b.getWidth() ), Math.round( scaleFactor*ip2b.getHeight() ) ) ) 

            # show images for debugging purposes
            # imp1a.show()
            # imp1b.show()
            # imp2a.show()
            # imp2b.show()

            

            img1a = ImagePlusAdapter.wrap(imp1a)
            img1b = ImagePlusAdapter.wrap(imp1b)
            img2a = ImagePlusAdapter.wrap(imp2a)