def vignettingFromRandomSteps(imgs, bg, inPlane_scale_factor=None, debugFolder=None, **kwargs): ''' important: first image should shown most iof the device because it is used as reference ''' # TODO: inPlane_scale_factor if debugFolder: debugFolder = PathStr(debugFolder) s = ObjectVignettingSeparation(imgs[0], bg, **kwargs) for img in imgs[1:]: fit = s.addImg(img) if debugFolder and fit is not False: imwrite(debugFolder.join('fit_%s.tiff' % len(s.fits)), fit) if debugFolder: imwrite(debugFolder.join('init.tiff'), s.flatField) smoothed_ff, mask, flatField, obj = s.separate() if debugFolder: imwrite(debugFolder.join('object.tiff'), obj) imwrite(debugFolder.join('flatfield.tiff'), flatField, dtype=float) imwrite(debugFolder.join('flatfield_smoothed.tiff'), smoothed_ff, dtype=float) return smoothed_ff, mask
def pathJoin(pathlist): if len(pathlist) > 5: mod, number, name, current, date = pathlist[:5] date = date.replace(':', '-') dd0 = '__'.join((number, name)) dd1 = '__'.join((current, date)) out = PathStr(mod).join(dd0, dd1) if len(pathlist[5:]): out = out.join(*tuple(pathlist[5:])) return out return PathStr(pathlist[0]).join(*pathlist[1:])
def pathJoin(pathlist): if len(pathlist) > 5: mod, number, name, current, date = pathlist[:5] # date = date.replace(':', '-') date = datetime.strptime(date, '%x %X').strftime("%Y-%m-%dT%H_%M_%S") dd0 = '__'.join((number, name)) dd1 = '__'.join((current, date)) out = PathStr(mod).join(dd0, dd1) if len(pathlist[5:]): out = out.join(*tuple(pathlist[5:])) return out return PathStr(pathlist[0]).join(*pathlist[1:])
def checkFolder(self): ''' Check for new files/folders in self.opts['folder'] and import them into dataArtist ''' fo = PathStr(self.opts['folder']) o = self.opts['files only'] files = fo.listdir() for f in files: if f not in self._files: ff = fo.join(f) if not o or ff.isfile(): self.gui.addFilePath(ff) self._files = files
final_img = final_img_crop return final_img else: return self.base_img_rgb if __name__ == '__main__': import sys import timeit import imgProcessor from fancytools.os.PathStr import PathStr d = PathStr(imgProcessor.__file__).dirname().join('media') i1 = cv2.imread(d.join('peanut_1.jpg')) i2 = cv2.imread(d.join('peanut_2.jpg')) def fn(overlap=None): # stitch 2 images taken in 2 different perspectives together: p = PerspectiveImageStitching(i1) fn.result = p.addImg(i2, overlap=overlap) # lets find out which method is faster: print(('time needed without given overlap [s]: ', timeit.timeit(fn, number=1))) print(('time needed with given overlap [s]: ', timeit.timeit(lambda: fn(overlap=150), number=1))) if 'no_window' not in sys.argv: cv2.namedWindow("warped")
arr = image[y0 - k:y0 + k, x0 - k:x0 + k] U = positionToIntensityUncertainty(arr, std / fx, std / fx) return U[k:-k, k:-k] if __name__ == '__main__': import sys import imgProcessor from imgProcessor.imgIO import imread from fancytools.os.PathStr import PathStr from pylab import plt d = PathStr(imgProcessor.__file__).dirname().join( 'media', 'electroluminescence') # STITCH BOTTOM img = imread(d.join('EL_cell_cracked.png'), 'gray') img = img[::2, ::2] # speed up for this test case # CASE 1: constant position uncertainty: stdx = 9 stdy = 3 sint = positionToIntensityUncertainty(img, stdx, stdy) # CASE2: variable position uncertainty: # x,y 0...15 stdx2 = np.fromfunction(lambda x, y: x * y, img.shape) stdx2 /= stdx2[-1, -1] / 9 stdy2 = np.fromfunction(lambda x, y: x * y, img.shape) stdy2 /= stdy2[-1, -1] / 9 stdy2 = stdy2[::-1, ::-1] # flip content twice
mask = np.logical_and(img2_cut == backgroundColor, img1_cut != backgroundColor) inter[mask] = img1_cut[mask] if not overlapping: overlap = 0 return np.vstack((img1[0:sizex - overlap, :], inter, img2[overlap:, :])) if __name__ == '__main__': import sys from fancytools.os.PathStr import PathStr from imgIO import imread import cv2 d = PathStr('').join('media', 'electroluminescence') i1 = d.join('EL_module_a_dist.PNG') i2 = d.join('EL_module_b_dist.PNG') img1 = imread(i1) / 2 img2 = imread(i2) cv2.namedWindow("stitched", cv2.cv.CV_WINDOW_NORMAL) s0 = img1.shape[0] for i in range(-s0, s0): img = linearBlend(img1, img2, i) if 'no_window' not in sys.argv: cv2.imshow('stitched', img) cv2.waitKey(delay=20) if 'no_window' not in sys.argv:
for l in self._linesFromvertices(self.vertices.astype(int)): cv2.line(img, tuple(l[:2]), tuple(l[2:]), color, thickness=thickness) return img if __name__ == '__main__': import sys import pylab as plt from fancytools.os.PathStr import PathStr import imgProcessor p = PathStr(imgProcessor.__file__).dirname().join( 'media', 'electroluminescence') img = p.join('EL_module_orig.PNG') q = QuadDetection(img) img = q.drawVertices() img2 = p.join('EL_cell_cracked.png') q = QuadDetection(img2) img2 = q.drawVertices(thickness=10) if 'no_window' not in sys.argv: plt.figure('module') plt.imshow(img) plt.figure('cell') plt.imshow(img2) plt.show()
ii += 1 return ii,jj if __name__ == '__main__': import sys import pylab as plt import imgProcessor from imgProcessor.imgIO import imread from fancytools.os.PathStr import PathStr p = PathStr(imgProcessor.__file__).dirname().join( 'media', 'electroluminescence') img = imread(p.join('EL_module_orig.PNG'), 'gray') #add nans img[300:310]=np.nan img[:,110:130]=np.nan bg = fastNaNmedianFilter(img,40,5) if 'no_window' not in sys.argv: plt.figure('image') plt.imshow(img, interpolation='none') plt.figure('background') plt.imshow(bg, interpolation='none') plt.figure('difference') plt.imshow(img-bg, interpolation='none')
def getBackgroundLevel(img): #seems to be best one according of no-ref bg comparison #as done for SNR article in BEDRICH2016 JPV return median_filter(img[10:-10:10,10:-10:10],7).min() if __name__ == '__main__': import sys from fancytools.os.PathStr import PathStr import imgProcessor from imgProcessor.imgIO import imread import pylab as plt p = PathStr(imgProcessor.__file__).dirname().join( 'media', 'electroluminescence') img = imread(p.join('EL_cell_cracked.png'), 'gray') snr = SNR(img) if 'no_window' not in sys.argv: plt.figure('image') plt.imshow(img) plt.colorbar() plt.figure('SNR') plt.imshow(snr) plt.colorbar() plt.show()
jj += 1 ii += 1 return ii, jj if __name__ == '__main__': import sys import pylab as plt import imgProcessor from imgProcessor.imgIO import imread from fancytools.os.PathStr import PathStr p = PathStr(imgProcessor.__file__).dirname().join('media', 'electroluminescence') img = imread(p.join('EL_module_orig.PNG'), 'gray') #add nans img[300:310] = np.nan img[:, 110:130] = np.nan bg = fastNaNmedianFilter(img, 40, 5) if 'no_window' not in sys.argv: plt.figure('image') plt.imshow(img, interpolation='none') plt.figure('background') plt.imshow(bg, interpolation='none') plt.figure('difference') plt.imshow(img - bg, interpolation='none')
offsx = int(round(loc[0] - ho)) offsy = overlapDeviation + overlap - loc[1] #print 'offset x:%s, y:%s, rotation:%s' %(offsx, offsy, angles[i]) return offsx, offsy, angles[i] if __name__ == '__main__': import sys import imgProcessor from fancytools.os.PathStr import PathStr d = PathStr(imgProcessor.__file__).dirname().join('media', 'electroluminescence') #STITCH BOTTOM i1 = d.join('EL_module_a_dist.PNG') i2 = d.join('EL_module_b_dist.PNG') i3 = d.join('EL_module_c.PNG') s = StitchImages(i1) stitched1 = s.addImg(i2, side='bottom', overlap=50, overlapDeviation=20) stitched1 = s.addImg(i3, side='bottom', overlap=50, overlapDeviation=20) #STITCH TOP s = StitchImages(i3) stitched2 = s.addImg(i2, side='top', overlap=50, overlapDeviation=20) stitched2 = s.addImg(i1, side='top', overlap=50, overlapDeviation=20) #STITCH RIGHT i1 = d.join('EL_module_a_dist2.PNG') i2 = d.join('EL_module_b_dist2.PNG')
return final_img else: return self.base_img_rgb if __name__ == '__main__': import sys import timeit import imgProcessor from fancytools.os.PathStr import PathStr d = PathStr(imgProcessor.__file__).dirname().join('media') i1 = cv2.imread(d.join('peanut_1.jpg')) i2 = cv2.imread(d.join('peanut_2.jpg')) def fn(overlap=None): #stitch 2 images taken in 2 different perspectives together: p = PerspectiveTransformation(i1) fn.result = p.addImg(i2, overlap=overlap) #lets find out which method is faster: print( 'time needed without given overlap [s]: ', timeit.timeit(fn, number=1) ) print( 'time needed with given overlap [s]: ', timeit.timeit(lambda: fn(overlap=150), number=1) ) if 'no_window' not in sys.argv:
inter, img2[overlap:, :])) if __name__ == '__main__': import sys from fancytools.os.PathStr import PathStr from imgProcessor.imgIO import imread import cv2 import imgProcessor d = PathStr( imgProcessor.__file__).dirname().join( 'media', 'electroluminescence') i1 = d.join('EL_module_a_dist.PNG') i2 = d.join('EL_module_b_dist.PNG') img1 = imread(i1) // 2 img2 = imread(i2) cv2.namedWindow("stitched") s0 = img1.shape[0] for i in range(-s0, s0): img = linearBlend(img1, img2, i) if 'no_window' not in sys.argv: cv2.imshow('stitched', img) cv2.waitKey(delay=20) if 'no_window' not in sys.argv:
########## #to allow to execute py code from a frozen environment #type e.g. gui.exe -exec print(4+4) if '-exec' in sys.argv: try: exec(sys.argv[-1]) except Exception, err: raw_input('-exec failed! --> %s' %err) sys.exit() ########## MEDIA_FOLDER = PathStr(dataArtist.__file__).dirname().join('media') HELP_FILE = MEDIA_FOLDER.join('USER_MANUAL.pdf') class Gui(MultiWorkspaceWindow): ''' The main class to be called to create an instance of dataArtist ''' def __init__(self, title='dataArtist'): MultiWorkspaceWindow.__init__(self, Workspace, title) s = self.app.session self.resize(600,550) #ALLOW DRAGnDROP self.setAcceptDrops(True) #INIT CHILD PARTS:
from dataArtist.widgets.GlobalTools import GlobalTools from dataArtist.widgets.StatusBar import StatusBar ########## #to allow to execute py code from a frozen environment #type e.g. gui.exe -exec print(4+4) if '-exec' in sys.argv: try: exec(sys.argv[-1]) except Exception, err: raw_input('-exec failed! --> %s' % err) sys.exit() ########## MEDIA_FOLDER = PathStr(dataArtist.__file__).dirname().join('media') HELP_FILE = MEDIA_FOLDER.join('USER_MANUAL.pdf') def _showActionToolTipInMenu(menu, action): #show tooltip on the right side of [menu] ###QMenu normaly doesnt allow QActions to show tooltips... tip = action.toolTip() # QtGui.QToolTip.showText(QtGui.QCursor.pos(), tip) p = menu.pos() p.setX(p.x() + 105) p.setY(p.y() - 21) if tip != action.text(): QtGui.QToolTip.showText(p, tip) class Gui(MultiWorkspaceWindow):
for i in xrange(orientations): out[:,:,i] = convolve2d(image, k[i], mode='same' ) return out if __name__ == '__main__': import sys from imgProcessor.imgIO import imread import pylab as plt from fancytools.os.PathStr import PathStr import imgProcessor p = PathStr(imgProcessor.__file__).dirname().join( 'media', 'electroluminescence') img = imread(p.join('EL_cell_cracked.PNG'), 'gray') k = (15,15) o = 4 p0=(141,91) p1=(251,242) p2=(667,570) kernels = _mkConvKernel(k, o, img) h = hog(img, ksize=k, orientations=o) if 'no_window' not in sys.argv: plt.figure('image') plt.imshow(img) plt.scatter(*p0) plt.scatter(*p1)
n += 1 if n > 0: out[i, j] = np.median(buff[:n]) if __name__ == '__main__': import sys import pylab as plt import imgProcessor from imgProcessor.imgIO import imread from fancytools.os.PathStr import PathStr p = PathStr(imgProcessor.__file__).dirname().join('media', 'electroluminescence') img = imread(p.join('EL_module_orig.PNG'), 'gray', dtype=float) # add nans img[300:320] = np.nan img[:, 110:130] = np.nan mask = np.isnan(img) bg1 = maskedFilter(img.copy(), mask, 80, fn='mean') bg2 = maskedFilter(img.copy(), mask, 80, fn='median') img2 = maskedFilter(img.copy(), mask, 80, fill_mask=False, fn='mean') if 'no_window' not in sys.argv: plt.figure('image') plt.imshow(img, interpolation='none') plt.colorbar()
''' Quantitative ElectroLuminescence Analysis ''' from fancytools.os.PathStr import PathStr name = 'QELA' __version__ = '-' # time stamp, set by server during packaging __author__ = 'Karl Bedrich' __email__ = '*****@*****.**' __license__ = 'GPLv3' # MEDIA_PATH = PathStr.getcwd().join('client', 'media') #only works if # executed from main dir MEDIA_PATH = PathStr(__file__).dirname().join( 'media') # TODO: works in FROZEN? ICON = MEDIA_PATH.join('logo.svg') PATH = PathStr.home().mkdir(".%s" % name)
n += 1 if n > 0: out[i, j] = np.median(buff[:n]) if __name__ == '__main__': import sys import pylab as plt import imgProcessor from imgProcessor.imgIO import imread from fancytools.os.PathStr import PathStr p = PathStr(imgProcessor.__file__).dirname().join( 'media', 'electroluminescence') img = imread(p.join('EL_module_orig.PNG'), 'gray', dtype=float) # add nans img[300:320] = np.nan img[:, 110:130] = np.nan mask = np.isnan(img) bg1 = maskedFilter(img.copy(), mask, 80, fn='mean') bg2 = maskedFilter(img.copy(), mask, 80, fn='median') img2 = maskedFilter(img.copy(), mask, 80, fill_mask=False, fn='mean') if 'no_window' not in sys.argv: plt.figure('image') plt.imshow(img, interpolation='none')