def computeSSF(img_name, filterSize=10, display=False, writeImage=False, verbose=False): # read image print "%s" % img_name src = cv2.imread(img_name, 0).astype(np.uint32) org = cv2.imread(img_name, 1) gray = cv2.imread(img_name, 0) # Area filter if verbose: print "Area Filter" AF_img = tos.areaFilter(src, size=filterSize) # Constructing tree of shapes if verbose: print "Constructing tree of shapes" padding_img = tos.imagePadding(AF_img, 0) tree = tos.constructTreeOfShapes(padding_img, None) # attribute if verbose: print "Adding area & depth attributes" tos.addAttributeArea(tree) tos.addAttributeDepth(tree) # generate graph and node position using NetworkX if verbose: print "Create Graph" g, nodePixMap = createAttributeGraph(tree, padding_img) # compute blobs and texture features if verbose: print "Compute blobs & features" dark, bright, fVector = drawBlobs(org, tree, g, nodePixMap, gray) # output name, ext = os.path.splitext(img_name) outName = name + ".csv" np.savetxt(outName, [fVector], delimiter=",") if verbose: print "%s; done." % img_name # write blob images if writeImage: cv2.imwrite("%s_dark.png" % name, dark) cv2.imwrite("%s_bright.png" % name, bright) # display if display: showImage(src, "src") showImage(AF_img, "area filter 1") cv2.imshow("dark_blobs", dark) cv2.imshow("bright_blobs", bright) cv2.waitKey() return tree, g, nodePixMap
def SitaElements(filename, filterSize=10, fcomb='SI'): """ This function outputs two numpy array objects: 1. SI or AI 2. Normalized gray level values (without generating CtH) fcomb: 'SI' or 'AI' SI = EH + CpH + SRH AI = EH + CpH """ src = cv2.imread(filename, 0).astype(np.uint32) # constructing tree of shapes AF_img = tos.areaFilter(src, size=filterSize) padding = tos.imagePadding(AF_img, 0) tree = tos.constructTreeOfShapes(padding, None) tos.addAttributeArea(tree) g, nodePixMap = createAttributeGraph(tree, padding) # remove padding (root) node removeEmptyRootNode(g, nodePixMap) # compute each attribute histogram EH, CpH, SRH, NL = computeSitaElementsFromTree(g, nodePixMap, AF_img) # selecting output feature if fcomb == 'AI': feature = np.r_[EH, CpH] elif fcomb == 'SI': feature = np.r_[EH, CpH, SRH] else: print "Wrong string is specified. 'SI' was selected." feature = np.r_[EH, CpH, SRH] # output basename, ext = os.path.splitext( filename ) if fcomb == 'AI': np.save( basename + "-AI.npy", feature ) elif fcomb == 'SI': np.save( basename + "-SI.npy", feature ) else: print "Wrong string is specified. 'SI' was selected." np.save( basename + "-SI.npy", feature ) np.save( basename + "-NL.npy", NL )
def SITA(filename, filterSize=10, fcomb='SI', isCtH=True): """ fcomb: 'SI' or 'AI' SI = EH + CpH + SRH AI = EH + CpH isCtH: boolian If isCtH is True, CtH is concatenated to SI or AI. """ src = cv2.imread(filename, 0).astype(np.uint32) # constructing tree of shapes AF_img = tos.areaFilter(src, size=filterSize) padding = tos.imagePadding(AF_img, 0) tree = tos.constructTreeOfShapes(padding, None) tos.addAttributeArea(tree) g, nodePixMap = createAttributeGraph(tree, padding) # remove paddint (root) node removeEmptyRootNode(g, nodePixMap) # compute each attribute histogram EH, CpH, SRH, NL = computeSitaElementsFromTree(g, nodePixMap, AF_img) # selecting output feature if fcomb == 'AI': feature = np.r_[EH, CpH] elif fcomb == 'SI': feature = np.r_[EH, CpH, SRH] else: print "Wrong string is specified. 'SI' was selected." feature = np.r_[EH, CpH, SRH] if isCtH: CtH = np.histogram(NL, bins=50, range=(NL_min, NL_max), normed=False)[0] if np.sum(CtH) == 0: CtH = np.zeros(50, dtype='float') else: CtH = CtH / float( np.linalg.norm(CtH, ord=1) ) feature = np.r_[feature, CtH] # output basename, ext = os.path.splitext( filename ) np.save( basename + "-SITA.npy", feature )