def analyseData(dd): #ss = dd.sum(0) #dnp.plot.image(ss) ##ss is the flat field print "Calculating median for the dataset ..." med = dnp.median(dd, 0) print "Median calculated" if plotData: dnp.plot.image(med) Sleep.sleep(2000) #flatFieldCorrectedSum = ss/med #dnp.plot.image(flatFieldCorrectedSum) xVals = [] yVals = [] ## print "Calculating centroid ..." centroids = [] for i in range(18): #dnp.plot.image(dd[i, :, :] / med) im = dd[i, :, :] / med im = javaImage.medianFilter(im, [3, 3]) im = dnp.array(im) threshold = 0.85 if plotData: dnp.plot.image(im) if plotData: Sleep.sleep(1000) if plotData: dnp.plot.image(im < threshold) if plotData: Sleep.sleep(1000) cent = dnp.centroid(im < threshold) yVals.append(cent[0]) xVals.append(cent[1]) centroids.append(cent) print "y:" + `yVals` print('') print "x:" + `xVals` #help(dnp.fit.ellipsefit) if plotData: dnp.plot.line(dnp.array(xVals), dnp.array(yVals)) ellipseFitValues = dnp.fit.ellipsefit(xVals, yVals) print "major: " + `ellipseFitValues[0]` print "minor semi-axis: " + `ellipseFitValues[1]` print "major axis angle: " + `ellipseFitValues[2]` print "centre co-ord 1: " + `ellipseFitValues[3]` print "centre co-ord 2: " + `ellipseFitValues[4]` print "centroids:" + `centroids` xOffset = getXOffset(ellipseFitValues[1], ellipseFitValues[0]) zOffset = getZOffset(ellipseFitValues[2]) return xOffset, zOffset, centroids, ellipseFitValues
def get_image_data( previewmean=False, preview_frames=True, visit_directory="/dls/i12/data/2014/cm4963-2/", flatfile=37384, projectionfile=37385, threshold=0.5, max_tries=15, prompt=False, request_input_command=request_DAWN_Input, ): working_directory = "%s/rawdata" % visit_directory flatfilename = "%s/%i.nxs" % (working_directory, flatfile) projectionfilename = "%s/%i.nxs" % (working_directory, projectionfile) # TODO put a unique time stamp on the otuput # TODO make a folder for the outputs print ("FlatFilename = %s" % flatfilename) print ("projectionfilename = %s" % projectionfilename) print "Loading flat field image %s\n\t to data processing pipeline" % flatfilename ff = None try_number = 0 while ff == None and try_number < max_tries: try_number += 1 try: print ("Trying to open the file %s" % (flatfilename)) data = dnp.io.load(flatfilename) ff = data["entry1"]["pco4000_dio_hdf"]["data"][...].mean(0) except: print ("ff is not null is it %s" % ff) print ("ff is not null is of type %s" % type(ff)) print ("Failed to load %i, will try again in 5 seconds" % (try_number)) time.sleep(5) ff = dnp.array(javaImage.medianFilter(ff._jdataset(), [3, 3])) dnp.plot.image(ff) time.sleep(5) print "Loading projections %s into data processing pipeline" % projectionfilename data = dnp.io.load(projectionfilename) try: dd = data["entry1"]["pco4000_dio_hdf"]["data"] except: print "Couldn not find the data in %s" % projectionfilename raise print "Processing data" # apply any filtering # exclude spheres which are not completely in the field of view if previewmean: print "slow look at all the data" preview = dd[:, :, :].mean(0) * 1.0 / ff dnp.plot.image(preview[10:-1, :]) time.sleep(2) print "Generating centroid data" thresholdOK = False xs = [] ys = [] while not thresholdOK: xs = [] ys = [] for i in range(dd.shape[0]): cor = dd[i, :, :] * 1.0 / ff # print "Applying median filter" cor = dnp.array(javaImage.medianFilter(cor._jdataset(), [3, 3])) cor = cor[10:-1, :] < threshold if preview_frames: dnp.plot.clear() time.sleep(0.01) dnp.plot.image(cor) time.sleep(0.2) y, x = dnp.centroid(cor) xs.append(x) ys.append(y) if prompt == False: thresholdOK = True else: response = request_input_command( "Current threshold is %f, y for ok, otherwise enter a new threshold value " % (threshold) ) if response == "y": thresholdOK = True else: try: threshold = float(response) except: print "could not interpret %s as a float" % response return (xs, ys)
def get_image_data(previewmean=False, preview_frames=True,visit_directory='/dls/i12/data/2014/cm4963-2/',flatfile=37384, projectionfile=37385, threshold=0.5, max_tries=15,prompt=False, request_input_command=request_DAWN_Input): working_directory="%s/rawdata"%visit_directory flatfilename="%s/%i.nxs"%(working_directory,flatfile) projectionfilename="%s/%i.nxs"%(working_directory,projectionfile) #TODO put a unique time stamp on the otuput #TODO make a folder for the outputs print("FlatFilename = %s"% flatfilename) print("projectionfilename = %s"% projectionfilename) print "Loading flat field image %s\n\t to data processing pipeline" % flatfilename ff = None try_number = 0 while (ff == None and try_number < max_tries): try_number += 1 try: print("Trying to open the file %s" % (flatfilename)) data = dnp.io.load(flatfilename) ff = data['entry1']['pco4000_dio_hdf']['data'][...].mean(0) except: print("ff is not null is it %s" % ff) print("ff is not null is of type %s" % type(ff)) print("Failed to load %i, will try again in 5 seconds" % (try_number)) time.sleep(5) ff = dnp.array(javaImage.medianFilter(ff._jdataset(), [3, 3])) dnp.plot.image(ff) time.sleep(5) print "Loading projections %s into data processing pipeline"% projectionfilename data = dnp.io.load(projectionfilename) try: dd = data['entry1']['pco4000_dio_hdf']['data'] except: print"Couldn not find the data in %s"%projectionfilename raise print "Processing data" # apply any filtering # exclude spheres which are not completely in the field of view if (previewmean): print "slow look at all the data" preview = dd[:,:,:].mean(0)*1.0/ff dnp.plot.image(preview[10:-1,:]) time.sleep(2) print "Generating centroid data" thresholdOK = False xs = [] ys = [] while not thresholdOK: xs = [] ys = [] for i in range(dd.shape[0]): cor = dd[i,:,:]*1.0/ff #print "Applying median filter" cor = dnp.array(javaImage.medianFilter(cor._jdataset(), [3, 3])) cor = cor[10:-1,:]<threshold if (preview_frames): dnp.plot.clear() time.sleep(0.01) dnp.plot.image(cor) time.sleep(.2) y,x = dnp.centroid(cor) xs.append(x) ys.append(y) if (prompt==False): thresholdOK=True else: response = request_input_command("Current threshold is %f, y for ok, otherwise enter a new threshold value " % (threshold)) if response == 'y' : thresholdOK = True else : try : threshold = float(response) except : print "could not interpret %s as a float" % response return(xs,ys)
def findshift(a, b, rect=None): '''Find translation vector from b to a using rectangular ROI rect''' return _image.findTranslation2D(a, b, rect)
def findshift(a, b, rect=None): """Find translation vector from b to a using rectangular ROI rect""" return _image.findTranslation2D(a, b, rect._jroi())