def preprocessing(self, imgs, msks, sz=(48, 48), augx=0): print len(imgs) if augx > 0: print "augmenting train data ..." # augx = 2xnSample+1 n_sample = np.int(augx / 2.0) - 1 imH, imW = imgs[0].shape[0:2] borderH = np.int(imH * 0.2) borderW = np.int(imW * 0.2) w = imW - borderW h = imH - borderH x1s = np.random.randint(0, borderW, n_sample) y1s = np.random.randint(0, borderH, n_sample) imgs_crop = imgs msks_crop = msks for img, msk in zip(imgs, msks): imgs_crop += [imcrop(img, [x1, y1, w, h]) for x1, y1 in zip(x1s, y1s)] msks_crop += [imcrop(msk, [x1, y1, w, h]) for x1, y1 in zip(x1s, y1s)] print len(imgs_crop) imgs_flip = [pl.fliplr(im) for im in imgs_crop] msks_flip = [pl.fliplr(im) for im in msks_crop] imgs = imgs_crop + imgs_flip msks = msks_crop + msks_flip print len(imgs) imgs_rs = [imresize(im, sz, interp="bicubic") for im in imgs] imgs_norm = [imnormalize(im) for im in imgs_rs] msks_norm = [imresize(im, sz, interp="bicubic") for im in msks] imgs_final, msks_final = self.convert_data(imgs_norm, msks_norm) print len(imgs_final) return imgs_final, msks_final
def vertFlipCheckBoxChanged(self, event): self.vertFlip = self.ui.vertFlipCheckBox.isChecked() if hasattr(self, 'meas'): self.plotImage(pl.fliplr(self.meas), autoLevels=self.autolevels, eqHist=self.equalizeHist, scale=self.scale)
def generate_masks(pattern,scattMaskRadius=50,scattMaskCenterX=523, scattMaskCenterY=523, background=30, slit=60): [dimy,dimx] = pattern.shape mask = euclid(dimx, dimx, scattMaskCenterX, scattMaskCenterY, scattMaskRadius) #mask[518:518+slit,:] = 0 #mask[370:480,520:650] = 0 #mask[:370,520:580] = 0 #mask[590:600,505:515] = 0 crosswidth = 10 shiftx = 10 shifty = 5 mask[512-crosswidth+shiftx:512+crosswidth+shiftx, :] = 0 mask[:, 512-crosswidth+shifty:512+crosswidth+shifty] = 0 mask[470:512, 400:512] = 0 mask = fliplr(rot90(mask,3)) H = numpy.array([map(float,line.strip('\n').split(',')) for line in filterwindow.split('\n')]) blurred = imfilter(mask,H) newMask = 1-(blurred<0.99) H2 = H newMask = imfilter(newMask.astype('double'), H2) #newMask = imfilter(newMask.astype('double'), H2) mask *= newMask gMask = gaussian_mask(dimx,dimx,400,700,300) centerMask = euclid(dimx,dimx,numpy.round(dimx/2),numpy.round(dimx/2),90) return mask, gMask, centerMask
def generate_masks(pattern,scattMaskRadius=50,scattMaskCenterX=523, scattMaskCenterY=523, background=30, slit=17): print 'getting shape' [dimy,dimx] = pattern.shape print 'mask bad areas' mask = euclid(dimx, dimx, scattMaskCenterX, scattMaskCenterY, scattMaskRadius) mask[518:518+slit,:] = 0 mask[370:480,520:650] = 0 mask[:370,520:580] = 0 mask[590:600,505:515] = 0 print 'doint some flipping...' mask = fliplr(rot90(mask,3)) # H = numpy.array([map(float,line.strip('\n').split(',')) for line in open('/Users/Goldmund/Documents/MATLAB/H.txt').readlines()]) print 'generate smear object' H = zeropad(strel(9, shape = 'disk'), mask.shape[0], mask.shape[1]) print 'broaden mask by blurring it' blurred = numpy.abs(myconv2(mask,H)) newMask = 1-(blurred<0.99) H2 = H print 'blurring new mask' newMask = numpy.abs(myconv2(newMask.astype('double'),H2)) mask *= newMask print 'creating gaussian and center mask' gMask = gaussian_mask(dimx,dimx,400,700,300) centerMask = euclid(dimx,dimx,numpy.round(dimx/2),numpy.round(dimx/2),150) return mask, gMask, centerMask
def generate_masks(pattern, scattMaskRadius=50, scattMaskCenterX=523, scattMaskCenterY=523, background=30, slit=60): [dimy, dimx] = pattern.shape mask = euclid(dimx, dimx, scattMaskCenterX, scattMaskCenterY, scattMaskRadius) #mask[518:518+slit,:] = 0 #mask[370:480,520:650] = 0 #mask[:370,520:580] = 0 #mask[590:600,505:515] = 0 crosswidth = 10 shiftx = 10 shifty = 5 mask[512 - crosswidth + shiftx:512 + crosswidth + shiftx, :] = 0 mask[:, 512 - crosswidth + shifty:512 + crosswidth + shifty] = 0 mask[470:512, 400:512] = 0 mask = fliplr(rot90(mask, 3)) H = numpy.array([ map(float, line.strip('\n').split(',')) for line in filterwindow.split('\n') ]) blurred = imfilter(mask, H) newMask = 1 - (blurred < 0.99) H2 = H newMask = imfilter(newMask.astype('double'), H2) #newMask = imfilter(newMask.astype('double'), H2) mask *= newMask gMask = gaussian_mask(dimx, dimx, 400, 700, 300) centerMask = euclid(dimx, dimx, numpy.round(dimx / 2), numpy.round(dimx / 2), 90) return mask, gMask, centerMask
def startAcq(self): """ Function called when pressing the Start button. Will launch the integration loop and stay going as long as no stopping action has happened (pressing Stop button, closing the window, changed integration time). """ self.ui.stopBut.setEnabled(True) self.ui.startBut.setEnabled(False) camId = self.ui.cameraID.value() try: with StarlightCCD(camId) as self.ccd: self.meas = pl.zeros((self.ccd.ccdParams['height'], self.ccd.ccdParams['width'])) i = 0 # flags for the event loop startThread = True # needs to start a new acquisition self.plotMeas = False # needs to plot the acquisition (acq finished) self.acquire = True # CCD should be acquiring # wait for a loop to finish while self.acquiring: pass self.acquiring = True # the event loop below is active # acquisition event loop while self.acquire: if startThread: ccdThread = ExposureThread( self.ccd, self.exposureTime, ilAcq=self.ilAcq, ilCorrDoubleExpo=self.ilDoubleExpo) ccdThread.start() startThread = False if self.capture and self.exposureTime > 1: self.captureStartSound.play() #print 'start sound' if not ccdThread.is_alive(): # acquisition finished self.plotMeas = True startThread = True if self.plotMeas: self.meas = ccdThread.ccd.pixels.transpose() if self.ccd.ccdParams[ 'isInterlaced'] and not self.ilAcq: ##not self.ilAcq and self.scale = (1, 2) else: self.scale = (1, 1) # flip image according to user specification # note that due to pyqtgraph behaviour, the array # columns are the rows in the displayed image if self.horizFlip: self.meas = pl.flipud(self.meas) if self.vertFlip: self.meas = pl.fliplr(self.meas) # plot image preview self.plotImage(self.meas, autoLevels=self.autolevels, eqHist=self.equalizeHist, scale=self.scale) if self.capture: self.captureStopSound.play() #print 'stop sound' break # will stop and record file in self.stop() else: self.plotMeas = False # go for another acquisition if ccdThread.ccd.completionPercentage == 100 or i % 100 == 0: self.ui.progressBar.setValue( ccdThread.ccd.completionPercentage) self.displayStats() # process events to catch a stop push and refresh image preview self.app.processEvents() i = i + 1 #self.ui.progressBar.setValue(0) ccdThread.stop() while ccdThread.is_alive(): # wait before closing device pass self.acquiring = False except IndexError: self.ui.modelName.setText('No device') self.ccd = None finally: self.stop(userStop=False)