def test2(mrc1, mrc2): import Mrc import correlator cor = correlator.Correlator() im1 = Mrc.mrc_to_numeric(mrc1) im2 = Mrc.mrc_to_numeric(mrc2) ''' im1 = im1[:512,:512] im2 = im2[200:712,200:712] ''' cor.insertImage(im1) cor.insertImage(im2) pc = cor.phaseCorrelate() Mrc.numeric_to_mrc(pc, 'pc.mrc') print findSubpixelPeak(pc, npix=7, lpf=1.0)
if fromrange is None: fromrange = image.getextrema() # ? image = scaleImage(image, fromrange, (0, 255)) return image.convert('RGB') def numpy2wxImage(*args, **kwargs): rgbimage = numpy2RGBImage(*args, **kwargs) wximage = wx.EmptyImage(*rgbimage.size) wximage.SetData(rgbimage.tostring()) return wximage def numpy2wxBitmap(*args, **kwargs): return wx.BitmapFromImage(numpy2wxImage(*args, **kwargs)) if __name__ == '__main__': import Mrc import sys array = Mrc.mrc_to_numeric(sys.argv[1]) #app = wx.App(0) #print numpy2wxBitmap(array) numpy2RGBImage(array).show()
sobel_row_kernel = numpy.array((1, 2, 1, 0, 0, 0, -1, -2, -1), numpy.float32) sobel_row_kernel.shape = (3, 3) #### Sobel Column Derivative sobel_col_kernel = numpy.array((1, 0, -1, 2, 0, -2, 1, 0, -1), numpy.float32) sobel_col_kernel.shape = (3, 3) if __name__ == '__main__': import Mrc import sys import imagefun filename = sys.argv[1] sobel_row = numpy.array((1, 2, 1, 0, 0, 0, -1, -2, -1), numpy.float32) sobel_row.shape = (3, 3) sobel_col = numpy.array((1, 0, -1, 2, 0, -2, 1, 0, -1), numpy.float32) sobel_col.shape = (3, 3) gauss = imagefun.gaussian_kernel(1.6) c = Convolver() im = Mrc.mrc_to_numeric(filename) c.setImage(image=im) s = c.convolve(kernel=gauss) r = c.convolve(kernel=sobel_row, image=s) c = c.convolve(kernel=sobel_col, image=s) edge = numpy.sqrt(r**2 + c**2) Mrc.numeric_to_mrc(edge, 'edge.mrc')
def threeD_MM(a, res, o, nAngles=2, verboseLvl=1, tmp='/tmp/'): import Mrc if o < 1: raise ValueError, "order need to >= 1" if nAngles < 1: raise ValueError, "nAngles need to >= 1" if verboseLvl >=1: import time startTime = time.clock() res[:] = 0 # aWV = Mrc.bindNew(tmp+"wvl_aWV", N.float32, a.shape) # aRot= Mrc.bindNew(tmp+"wvl_aRot", N.float32, a.shape) # c = Mrc.bindNew(tmp+"wvl_c", N.float32, a.shape) aWV = F.zeroArrF(a.shape) angles = N.arange(90./nAngles, 90., 90./nAngles) nOffAngles = len(angles) # = nAngles -1 # do first fastwv6 on original data if verboseLvl >=1: print "begin angle 0" if verboseLvl >=2: print print " perm " Y.refresh() for i in range(len(_perm)): if verboseLvl >=2: print " ", i Y.refresh() tmpTrans = N.transpose(a, _perm[i]).copy() # force contiguous! aWV.shape = tmpTrans.shape W.fastwv6(tmpTrans,aWV, o,o,o, verboseLvl>=3) tmpTrans = N.transpose(aWV,_invperm[i]) tmpTrans /= len(_perm) * (1 + (nOffAngles * 3)) res += tmpTrans # now do it for a bunch of angles if len(angles): c = Mrc.bindNew(tmp+"wvl_c", N.float32, a.shape) for angle in angles: for axis in (0,1,2): if verboseLvl >=1: print "begin angle ",angle print " axis:", axis Y.refresh() aRot = aWV U.rot3d(a,aRot, angle, axis) if verboseLvl >=2: print " perm " c[:] = 0 for i in range(len(_perm)): #dbg print " perm:", i if verboseLvl >=2: print " ", i Y.refresh() tmpTrans = N.transpose(aRot, _perm[i]).copy() # force contiguous! aWV.shape = tmpTrans.shape W.fastwv6(tmpTrans,aWV, o,o,o, verboseLvl>=3) tmpTrans = N.transpose(aWV,_invperm[i]) tmpTrans /= len(_perm) * (1 + (nOffAngles * 3)) c += tmpTrans U.rot3d(c,aRot,-angle,axis) res += aRot if verboseLvl >=1: print if verboseLvl >=1: import time d = time.clock()-startTime print "time: %.2lf secs - %.2lf min - %.2lf h " % (d, d/60., d/60./60.)
sobel_row_kernel.shape = (3,3) #### Sobel Column Derivative sobel_col_kernel = numpy.array((1,0,-1,2,0,-2,1,0,-1), numpy.float32) sobel_col_kernel.shape = (3,3) if __name__ == '__main__': import Mrc import sys import imagefun filename = sys.argv[1] sobel_row = numpy.array((1,2,1,0,0,0,-1,-2,-1), numpy.float32) sobel_row.shape = (3,3) sobel_col = numpy.array((1,0,-1,2,0,-2,1,0,-1), numpy.float32) sobel_col.shape = (3,3) gauss = imagefun.gaussian_kernel(1.6) c = Convolver() im = Mrc.mrc_to_numeric(filename) c.setImage(image=im) s = c.convolve(kernel=gauss) r = c.convolve(kernel=sobel_row, image=s) c = c.convolve(kernel=sobel_col, image=s) edge = numpy.sqrt(r**2 + c**2) Mrc.numeric_to_mrc(edge, 'edge.mrc')
image = image.transform((width, height), Image.EXTENT, (left, upper, right, bottom), filter) if fromrange is None: fromrange = image.getextrema() # ? image = scaleImage(image, fromrange, (0, 255)) return image.convert('RGB') def numarray2wxImage(*args, **kwargs): rgbimage = numarray2RGBImage(*args, **kwargs) wximage = wx.EmptyImage(*rgbimage.size) wximage.SetData(rgbimage.tostring()) return wximage def numarray2wxBitmap(*args, **kwargs): return wx.BitmapFromImage(numarray2wxImage(*args, **kwargs)) if __name__ == '__main__': import Mrc import sys array = Mrc.mrc_to_numeric(sys.argv[1]) #app = wx.App(0) #print numarray2wxBitmap(array) numarray2RGBImage(array).show()
def load_mrc( mrcfn): stack = Mrc.load(mrcfn) return stack
def write_mrc(stack, mrcfn): #stackf32 = stack.astype(np.float32) Mrc.save(stack, mrcfn,ifExists='overwrite',calcMMM=False)