def loadBSQ(path = '/home/crob/HyperSpec_Data/WBC v ALL/WBC25', debug=False): d31 = [] d31_norm = [] d25 = [] d25_norm = [] l25 = [] l = [] l3 = [] lam = [] for root, dirs, files in os.walk(path): print(dirs) for name in sorted(files): #os walk iterates arbitrarily, sort fixes it print(name) if name.endswith(".png"): # Import label image im = np.array(Image.open(os.path.join(root,name)),'f') print np.shape(im) im = im[:,:,0:3] # > 250 # generate a mask for 3x3 conv layer (probably not needed) #conv3bw = signal.convolve2d(bw, np.ones([22,22],dtype=np.int), mode='valid') >= 464 print(np.shape(im)) #p = open(name+'_22sqMask.png','wb') #w = png.Writer(255) #bw = np.flipud(bw) im = np.flipud(im) #l3.append(np.reshape(conv3bw, )) #l.append(np.reshape(bw, 138659)) l.append(im) print(np.shape(im)) print("Name = " + name) if name.endswith(".bsq"): bs = bsq.readbsq(os.path.join(root,name)) print(np.shape(bs[0])) print(len(bs[1])) #separate bsq files by prism if len(bs[1]) == 31: print('BSQ is size 31') print(len(bs[1])) lam = bs[1] #d31.append(np.reshape(np.transpose(bs[0], (1, 2, 0)), 4298429)) d31.append(bs[0].astype(np.float32)) d31_norm.append(bs[0].astype(np.float32)/np.amax(bs[0])) if len(bs[1]) == 25: print('BSQ is size 25') print(len(bs[1])) lam = bs[1] d25.append(bs[0].astype(np.float32)) d25_norm.append(bs[0].astype(np.float32)/np.amax(bs[0])) #d25.append(np.reshape(bs[0],[138659,25]).astype(np.float32)) # old don't use #d25.append(np.reshape(np.transpose(bs[0], (1, 2, 0)), 3466475)) out = collections.namedtuple('examples', ['data31', 'data31_norm', 'data25', 'data25_norm', 'labels', 'lambdas']) o = out(data31=np.dstack(d31),data31_norm=np.dstack(d31_norm), data25=d25, data25_norm=d25_norm, labels=np.dstack(l), lambdas=lam) #np.vstack(d25), labels=np.hstack(l) return o
def readBsqToObj(path,mPath): dCube = dataCube() (dCube.HSData, dCube.Lambdas) = BSQ.readbsq(dir) #add in line to read in mask image return dCube
scipy.misc.imsave(pathName + '\\processed_masks\\' + maskNames[i][2:-8] + '.png', im) # im = skimage.io.imread(mFile, plugin='tifffile') A = dataCube(maskNames[i][2:-8], None, None, im) print(A.MaskData.shape) maskList.append(A) ## insert for loop here (add if statement) #This loop runs when looking in BSQ Directory if dirs == 'bsq': for i in range(0,bsqCount): dir = os.path.dirname(os.path.join(sDir,objNames[i])) print(str(maskCount)) if not os.path.exists(dir+'/TIF/'): os.mkdir(dir+'/TIF/') #outfile = dir + '/TIF/' + os.path.basename(os.path.join(sDir,objNames[i]))[:-4] (dcb, lambdas) = BSQ.readbsq(os.path.join(sDir,objNames[i])) #print('dcb.shape=', dcb.shape) #print('dcb.dtype=', dcb.dtype) #print('lambdas=', lambdas) # Convert type double pixel data to type uint16 for exporting to TIFF. minval = np.amin(dcb) maxval = np.amax(dcb) #print('original dcb: minval=%f, maxval=%f' % (minval, maxval)) new_dcb = np.int16((dcb - minval) * (2**15 - 1) / np.float64(maxval - minval)) #print('new_dcb.dtype=', new_dcb.dtype) #print('rescaled dcb: minval=%i, maxval=%i' % (amin(new_dcb), amax(new_dcb))) img = new_dcb[:, :, 0]
def loadBSQ(path='/home/crob/HyperSpec_Data/WBC v ALL/WBC25', debug=False): d31 = [] d31_norm = [] d25 = [] d25_norm = [] l25 = [] l = [] l3 = [] lam = [] for root, dirs, files in os.walk(path): print(dirs) for name in sorted( files): #os walk iterates arbitrarily, sort fixes it print(name) if name.endswith(".png"): # Import label image im = np.array(Image.open(os.path.join(root, name)), 'f') print np.shape(im) im = im[:, :, 0:3] # > 250 # generate a mask for 3x3 conv layer (probably not needed) #conv3bw = signal.convolve2d(bw, np.ones([22,22],dtype=np.int), mode='valid') >= 464 print(np.shape(im)) #p = open(name+'_22sqMask.png','wb') #w = png.Writer(255) #bw = np.flipud(bw) im = np.flipud(im) #l3.append(np.reshape(conv3bw, )) #l.append(np.reshape(bw, 138659)) l.append(im) print(np.shape(im)) print("Name = " + name) if name.endswith(".bsq"): bs = bsq.readbsq(os.path.join(root, name)) print(np.shape(bs[0])) print(len(bs[1])) #separate bsq files by prism if len(bs[1]) == 31: print('BSQ is size 31') print(len(bs[1])) lam = bs[1] #d31.append(np.reshape(np.transpose(bs[0], (1, 2, 0)), 4298429)) d31.append(bs[0].astype(np.float32)) d31_norm.append(bs[0].astype(np.float32) / np.amax(bs[0])) if len(bs[1]) == 25: print('BSQ is size 25') print(len(bs[1])) lam = bs[1] d25.append(bs[0].astype(np.float32)) d25_norm.append(bs[0].astype(np.float32) / np.amax(bs[0])) #d25.append(np.reshape(bs[0],[138659,25]).astype(np.float32)) # old don't use #d25.append(np.reshape(np.transpose(bs[0], (1, 2, 0)), 3466475)) out = collections.namedtuple('examples', [ 'data31', 'data31_norm', 'data25', 'data25_norm', 'labels', 'lambdas' ]) o = out(data31=np.dstack(d31), data31_norm=np.dstack(d31_norm), data25=d25, data25_norm=d25_norm, labels=np.dstack(l), lambdas=lam) #np.vstack(d25), labels=np.hstack(l) return o