Commit 2c44046d authored by Andrey Filippov's avatar Andrey Filippov

Updating for LWIR data

parent d5384e3f
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -55,19 +55,63 @@ class bcolors: ...@@ -55,19 +55,63 @@ class bcolors:
BOLD = '\033[1m' BOLD = '\033[1m'
BOLDWHITE = '\033[1;37m' BOLDWHITE = '\033[1;37m'
UNDERLINE = '\033[4m' UNDERLINE = '\033[4m'
class IJML:
# as devined in ImageDtt.java
ML_OTHER_TARGET = 0 # Offset to target disparity data in ML_OTHER_INDEX layer tile
ML_OTHER_GTRUTH = 2 # Offset to ground truth disparity data in ML_OTHER_INDEX layer tile
ML_OTHER_GTRUTH_STRENGTH = 4 # Offset to ground truth confidence data in ML_OTHER_INDEX layer tile
ML_OTHER_GTRUTH_RMS = 6 # Offset to ground truth RMS in ML_OTHER_INDEX layer tile
ML_OTHER_GTRUTH_RMS_SPLIT = 8 # Offset to ground truth combined FG/BG RMS in ML_OTHER_INDEX layer tile
ML_OTHER_GTRUTH_FG_DISP = 10 # Offset to ground truth FG disparity in ML_OTHER_INDEX layer tile
ML_OTHER_GTRUTH_FG_STR = 12 # Offset to ground truth FG strength in ML_OTHER_INDEX layer tile
ML_OTHER_GTRUTH_BG_DISP = 14 # Offset to ground truth BG disparity in ML_OTHER_INDEX layer tile
ML_OTHER_GTRUTH_BG_STR = 16 # Offset to ground truth BG strength in ML_OTHER_INDEX layer tile
ML_OTHER_AUX_DISP = 18 # Offset to AUX heuristic disparity in ML_OTHER_INDEX layer tile
ML_OTHER_AUX_STR = 20 # Offset to AUX heuristic strength in ML_OTHER_INDEX layer tile
# indices
TARGET = ML_OTHER_TARGET // 2
GTRUTH = ML_OTHER_GTRUTH // 2
STRENGTH = ML_OTHER_GTRUTH_STRENGTH // 2
RMS = ML_OTHER_GTRUTH_RMS // 2
RMS_SPLIT = ML_OTHER_GTRUTH_RMS_SPLIT // 2
FG_DISP = ML_OTHER_GTRUTH_FG_DISP // 2
FG_STR = ML_OTHER_GTRUTH_FG_STR // 2
BG_DISP = ML_OTHER_GTRUTH_BG_DISP // 2
BG_STR = ML_OTHER_GTRUTH_BG_STR // 2
AUX_DISP = ML_OTHER_AUX_DISP // 2
AUX_STR = ML_OTHER_AUX_STR // 2
SIGNED = (TARGET, GTRUTH, FG_DISP, BG_DISP)
UNSIGNED_RMS = (RMS, RMS_SPLIT)
NUM_VALUES = 11
class IJFGBG:
DSI_NAMES = ["disparity","strength","rms","rms-split","fg-disp","fg-str","bg-disp","bg-str","aux-disp","aux-str"]
DISPARITY = 0
STRENGTH = 1
RMS = 2
RMS_SPLIT = 3
FG_DISP = 4
FG_STR = 5
BG_DISP = 6
BG_STR = 7
AUX_DISP = 8
AUX_STR = 9
# reshape to tiles # reshape to tiles
def get_tile_images(image, width=8, height=8): def get_tile_images(image, width=8, height=8):
_nrows, _ncols, depth = image.shape _nrows, _ncols, depth = image.shape
_size = image.size _size = image.size
_strides = image.strides _strides = image.strides
nrows, _m = divmod(_nrows, height) nrows, _m = divmod(_nrows, height)
ncols, _n = divmod(_ncols, width) ncols, _n = divmod(_ncols, width)
if _m != 0 or _n != 0: if _m != 0 or _n != 0:
return None return None
return np.lib.stride_tricks.as_strided( return np.lib.stride_tricks.as_strided(
np.ravel(image), np.ravel(image),
shape=(nrows, ncols, height, width, depth), shape=(nrows, ncols, height, width, depth),
strides=(height * _strides[0], width * _strides[1], *_strides), strides=(height * _strides[0], width * _strides[1], *_strides),
...@@ -95,460 +139,463 @@ Examples: ...@@ -95,460 +139,463 @@ Examples:
''' '''
class imagej_tiff: class imagej_tiff:
# imagej stores labels lengths in this tag
# imagej stores labels lengths in this tag __TIFF_TAG_LABELS_LENGTHS = 50838
__TIFF_TAG_LABELS_LENGTHS = 50838 # imagej stores labels conents in this tag
# imagej stores labels conents in this tag __TIFF_TAG_LABELS_STRINGS = 50839
__TIFF_TAG_LABELS_STRINGS = 50839
# init
# init def __init__(self,filename, layers = None, tile_list = None):
def __init__(self,filename, layers = None, tile_list = None): # file name
# file name self.fname = filename
self.fname = filename tif = Image.open(filename)
tif = Image.open(filename) # total number of layers in tiff
# total number of layers in tiff self.nimages = tif.n_frames
self.nimages = tif.n_frames # labels array
# labels array self.labels = []
self.labels = [] # infos will contain xml data Elphel stores in some of tiff files
# infos will contain xml data Elphel stores in some of tiff files self.infos = []
self.infos = [] # dictionary from decoded infos[0] xml data
# dictionary from decoded infos[0] xml data self.props = {}
self.props = {}
# bits per sample, type int
# bits per sample, type int self.bpp = tif.tag[258][0]
self.bpp = tif.tag[258][0]
self.__split_labels(tif.n_frames,tif.tag)
self.__split_labels(tif.n_frames,tif.tag) self.__parse_info()
self.__parse_info() try:
try: self.nan_bug = self.props['VERSION']== '1.0' # data between min and max is mapped to 0..254 instead of 1.255
self.nan_bug = self.props['VERSION']== '1.0' # data between min and max is mapped to 0..254 instead of 1.255 except:
except: self.nan_bug = False # other files, not ML ones
self.nan_bug = False # other files, not ML ones # image layers stacked along depth - (think RGB)
# image layers stacked along depth - (think RGB) self.image = []
self.image = []
if layers is None:
if layers is None: # fill self.image
# fill self.image for i in range(self.nimages):
for i in range(self.nimages): tif.seek(i)
tif.seek(i)
a = np.array(tif)
a = np.reshape(a,(a.shape[0],a.shape[1],1))
#a = a[:,:,np.newaxis]
# scale for 8-bits
# exclude layer named 'other'
if self.bpp==8:
_min = self.data_min
_max = self.data_max
_MIN = 1
_MAX = 255
if (self.nan_bug):
_MIN = 0
_MAX = 254
else:
if self.labels[i]!='other':
a[a==0]=np.nan
a = a.astype(float)
if self.labels[i]!='other':
# a[a==0]=np.nan
a = (_max-_min)*(a-_MIN)/(_MAX-_MIN)+_min
# init
if i==0:
self.image = a
# stack along depth (think of RGB channels)
else:
self.image = np.append(self.image,a,axis=2)
else:
if tile_list is None:
indx = 0
for layer in layers:
tif.seek(self.labels.index(layer))
a = np.array(tif) a = np.array(tif)
if not indx: a = np.reshape(a,(a.shape[0],a.shape[1],1))
self.image = np.empty((a.shape[0],a.shape[1],len(layers)),a.dtype) #a = a[:,:,np.newaxis]
self.image[...,indx] = a # scale for 8-bits
indx += 1 # exclude layer named 'other'
if self.bpp==8:
_min = self.data_min
_max = self.data_max
_MIN = 1
_MAX = 255
if (self.nan_bug):
_MIN = 0
_MAX = 254
else:
if self.labels[i]!='other':
a[a==0]=np.nan
a = a.astype(float)
if self.labels[i]!='other':
# a[a==0]=np.nan
a = (_max-_min)*(a-_MIN)/(_MAX-_MIN)+_min
# init
if i==0:
self.image = a
# stack along depth (think of RGB channels)
else:
self.image = np.append(self.image,a,axis=2)
else: else:
other_label = "other" if tile_list is None:
# print(tile_list) indx = 0
num_tiles = len(tile_list) for layer in layers:
num_layers = len(layers) tif.seek(self.labels.index(layer))
tiles_corr = np.empty((num_tiles,num_layers,self.tileH*self.tileW),dtype=float) a = np.array(tif)
# tiles_other=np.empty((num_tiles,3),dtype=float) if not indx:
tiles_other=self.gettilesvalues( self.image = np.empty((a.shape[0],a.shape[1],len(layers)),a.dtype)
tif = tif, self.image[...,indx] = a
tile_list=tile_list, indx += 1
label=other_label) else:
for nl,label in enumerate(layers): other_label = "other"
tif.seek(self.labels.index(label)) # print(tile_list)
layer = np.array(tif) # 8 or 32 bits num_tiles = len(tile_list)
tilesX = layer.shape[1]//self.tileW num_layers = len(layers)
for nt,tl in enumerate(tile_list): tiles_corr = np.empty((num_tiles,num_layers,self.tileH*self.tileW),dtype=float)
ty = tl // tilesX # tiles_other=np.empty((num_tiles,3),dtype=float)
tx = tl % tilesX tiles_other=self.gettilesvalues( # returns nparray of 11 floats (was 3)
# tiles_corr[nt,nl] = np.ravel(layer[self.tileH*ty:self.tileH*(ty+1),self.tileW*tx:self.tileW*(tx+1)]) tif = tif,
a = np.ravel(layer[self.tileH*ty:self.tileH*(ty+1),self.tileW*tx:self.tileW*(tx+1)]) tile_list=tile_list,
#convert from int8 label=other_label)
if self.bpp==8: for nl,label in enumerate(layers):
a = a.astype(float) tif.seek(self.labels.index(label)) #'hor-pairs' is not in list
if np.isnan(tiles_other[nt][0]): layer = np.array(tif) # 8 or 32 bits
# print("Skipping NaN tile ",tl) tilesX = layer.shape[1]//self.tileW
a[...] = np.nan for nt,tl in enumerate(tile_list):
else: ty = tl // tilesX
_min = self.data_min tx = tl % tilesX
_max = self.data_max a = np.ravel(layer[self.tileH * ty : self.tileH * (ty+1),
_MIN = 1 self.tileW * tx : self.tileW * (tx+1)])
_MAX = 255 #convert from int8
if (self.nan_bug): if self.bpp==8:
_MIN = 0 a = a.astype(float)
_MAX = 254 if np.isnan(tiles_other[nt][0]):
else: # print("Skipping NaN tile ",tl)
a[a==0] = np.nan a[...] = np.nan
a = (_max-_min)*(a-_MIN)/(_MAX-_MIN)+_min else:
tiles_corr[nt,nl] = a _min = self.data_min
_max = self.data_max
_MIN = 1
_MAX = 255
if (self.nan_bug):
_MIN = 0
_MAX = 254
else:
a[a==0] = np.nan
a = (_max-_min)*(a-_MIN)/(_MAX-_MIN)+_min
tiles_corr[nt,nl] = a
pass
pass pass
self.corr2d = tiles_corr
self.target_disparity = tiles_other[...,0]
self.gt_ds = tiles_other[...,1:3]
self.payload = tiles_other#[...,0:12]
pass pass
self.corr2d = tiles_corr
self.target_disparity = tiles_other[...,0] # init done, close the image
self.gt_ds = tiles_other[...,1:3] tif.close()
pass
# init done, close the image
tif.close()
# label == tiff layer name
def getvalues(self,label=""):
l = self.getstack([label],shape_as_tiles=True)
res = np.empty((l.shape[0],l.shape[1],3))
for i in range(res.shape[0]):
for j in range(res.shape[1]):
# 9x9 -> 81x1
m = np.ravel(l[i,j])
if self.bpp==32:
res[i,j,0] = m[0]
res[i,j,1] = m[2]
res[i,j,2] = m[4]
elif self.bpp==8:
res[i,j,0] = ((m[0]-128)*256+m[1])/128
res[i,j,1] = ((m[2]-128)*256+m[3])/128
res[i,j,2] = (m[4]*256+m[5])/65536.0
else:
res[i,j,0] = np.nan
res[i,j,1] = np.nan
res[i,j,2] = np.nan
# NaNize
a = res[:,:,0]
a[a==-256] = np.nan
b = res[:,:,1]
b[b==-256] = np.nan
c = res[:,:,2]
c[c==0] = np.nan
return res
# 3 values per tile: target disparity, GT disparity, GT confidence # label == tiff layer name
def gettilesvalues(self, def getvalues(self,label=""):
l = self.getstack([label],shape_as_tiles=True)
res = np.empty((l.shape[0],l.shape[1], IJML.NUM_VALUES)) # was just 3
for i in range(res.shape[0]):
for j in range(res.shape[1]):
# 9x9 -> 81x1
m = np.ravel(l[i,j])
if self.bpp==32:
for k in range(res.shape[2]):
res[i,j,k] = m[k * 2]
elif self.bpp==8:
for k in range(res.shape[2]):
if k in IJML.SIGNED:
res[i,j,k] = ((m[2 * k] - 128) * 256 + m[2 * k + 1]) / 128
elif k in IJML.UNSIGNED_RMS:
res[i,j,k] = (m[2 * k]*256+m[2 * k + 1])/4096.0
else:
res[i,j,k] = (m[2 * k]*256+m[2 * k + 1])/65536.0
else:
for k in range(res.shape[2]):
res[i,j,k] = np.nan
# NaNize - TODO: update !
if self.bpp==8:
a = res[:,:,0]
a[a==-256] = np.nan
b = res[:,:,1]
b[b==-256] = np.nan
c = res[:,:,2]
c[c==0] = np.nan
return res
# 3 values per tile: target disparity, GT disparity, GT confidence
# With LWIR/aux there are more!
def gettilesvalues(self,
tif, tif,
tile_list, tile_list,
label=""): label=""):
res = np.empty((len(tile_list),3),dtype=float) res = np.empty((len(tile_list), IJML.NUM_VALUES),dtype=float) # was only 3
tif.seek(self.labels.index(label)) tif.seek(self.labels.index(label))
layer = np.array(tif) # 8 or 32 bits layer = np.array(tif) # 8 or 32 bits
tilesX = layer.shape[1]//self.tileW tilesX = layer.shape[1]//self.tileW
for i,tl in enumerate(tile_list): for i,tl in enumerate(tile_list):
ty = tl // tilesX ty = tl // tilesX
tx = tl % tilesX tx = tl % tilesX
m = np.ravel(layer[self.tileH*ty:self.tileH*(ty+1),self.tileW*tx:self.tileW*(tx+1)]) m = np.ravel(layer[self.tileH*ty:self.tileH*(ty+1),self.tileW*tx:self.tileW*(tx+1)])
if self.bpp==32: if self.bpp==32:
res[i,0] = m[0] for k in range(res.shape[1]):
res[i,1] = m[2] res[i,k] = m[k * 2]
res[i,2] = m[4] elif self.bpp==8:
elif self.bpp==8: for k in range(res.shape[1]):
res[i,0] = ((m[0]-128)*256+m[1])/128 if k in IJML.SIGNED:
res[i,1] = ((m[2]-128)*256+m[3])/128 res[i,k] = ((m[2 * k] - 128) * 256 + m[2 * k + 1]) / 128
res[i,2] = (m[4]*256+m[5])/65536.0 elif k in IJML.UNSIGNED_RMS:
res[i,k] = (m[2 * k]*256+m[2 * k + 1])/4096.0
else:
res[i,k] = (m[2 * k]*256+m[2 * k + 1])/65536.0
else:
for k in range(res.shape[1]):
res[i,k] = np.nan
# NaNize update!
if self.bpp==8:
a = res[...,0]
a[a==-256] = np.nan
b = res[...,1]
b[b==-256] = np.nan
c = res[...,2]
c[c==0] = np.nan
return res
# get ordered stack of images by provided items
# by index or label name
def getstack(self,items=[],shape_as_tiles=False):
a = ()
if len(items)==0:
b = self.image
else: else:
res[i,0] = np.nan for i in items:
res[i,1] = np.nan if type(i)==int:
res[i,2] = np.nan a += (self.image[:,:,i],)
# NaNize elif type(i)==str:
a = res[...,0] j = self.labels.index(i)
a[a==-256] = np.nan a += (self.image[:,:,j],)
b = res[...,1] # stack along depth
b[b==-256] = np.nan b = np.stack(a,axis=2)
c = res[...,2]
c[c==0] = np.nan if shape_as_tiles:
b = get_tile_images(b,self.tileW,self.tileH)
return res
return b
# get np.array of a channel
# * does not handle out of bounds
# get ordered stack of images by provided items def channel(self,index):
# by index or label name return self.image[:,:,index]
def getstack(self,items=[],shape_as_tiles=False):
a = ()
if len(items)==0: # display images by index or label
b = self.image def show_images(self,items=[]):
else: # show listed only
for i in items: if len(items)>0:
if type(i)==int: for i in items:
a += (self.image[:,:,i],) if type(i)==int:
elif type(i)==str: self.show_image(i)
j = self.labels.index(i) elif type(i)==str:
a += (self.image[:,:,j],) j = self.labels.index(i)
# stack along depth self.show_image(j)
b = np.stack(a,axis=2) # show all
else:
if shape_as_tiles: for i in range(self.nimages):
b = get_tile_images(b,self.tileW,self.tileH) self.show_image(i)
return b
# display single image
# get np.array of a channel def show_image(self,index):
# * do not handle out of bounds # display using matplotlib
def channel(self,index): t = self.image[:,:,index]
return self.image[:,:,index] mytitle = "("+str(index+1)+" of "+str(self.nimages)+") "+self.labels[index]
fig = plt.figure()
fig.canvas.set_window_title(self.fname+": "+mytitle)
# display images by index or label fig.suptitle(mytitle)
def show_images(self,items=[]): #plt.imshow(t,cmap=plt.get_cmap('gray'))
plt.imshow(t)
# show listed only plt.colorbar()
if len(items)>0:
for i in items: # display using Pillow - need to scale
if type(i)==int:
self.show_image(i) # remove NaNs - no need
elif type(i)==str: #t[np.isnan(t)]=np.nanmin(t)
j = self.labels.index(i) # scale to [min/max*255:255] range
self.show_image(j) #t = (1-(t-np.nanmax(t))/(t-np.nanmin(t)))*255
# show all #tmp_im = Image.fromarray(t)
else: #tmp_im.show()
for i in range(self.nimages):
self.show_image(i) # puts etrees in infoss
def __parse_info(self):
infos = []
# display single image for info in self.infos:
def show_image(self,index): infos.append(ET.fromstring(info))
# display using matplotlib self.infos = infos
t = self.image[:,:,index] # specifics
mytitle = "("+str(index+1)+" of "+str(self.nimages)+") "+self.labels[index] # properties dictionary
fig = plt.figure() pd = {}
fig.canvas.set_window_title(self.fname+": "+mytitle)
fig.suptitle(mytitle) if infos:
#plt.imshow(t,cmap=plt.get_cmap('gray')) for child in infos[0]:
plt.imshow(t) #print(child.tag+"::::::"+child.text)
plt.colorbar() pd[child.tag] = child.text
# display using Pillow - need to scale self.props = pd
# remove NaNs - no need # tiles are squares
#t[np.isnan(t)]=np.nanmin(t) self.tileW = int(self.props['tileWidth'])
# scale to [min/max*255:255] range self.tileH = int(self.props['tileWidth'])
#t = (1-(t-np.nanmax(t))/(t-np.nanmin(t)))*255 if self.bpp==8:
#tmp_im = Image.fromarray(t) self.data_min = float(self.props['data_min'])
#tmp_im.show() self.data_max = float(self.props['data_max'])
# puts etrees in infoss # makes arrays of labels (strings) and unparsed xml infos
def __parse_info(self): def __split_labels(self,n,tag):
# list
infos = [] tag_lens = tag[self.__TIFF_TAG_LABELS_LENGTHS]
for info in self.infos: # string
infos.append(ET.fromstring(info)) tag_labels = tag[self.__TIFF_TAG_LABELS_STRINGS].decode()
# remove 1st element: it's something like IJIJlabl..
self.infos = infos tag_labels = tag_labels[tag_lens[0]:]
tag_lens = tag_lens[1:]
# specifics
# properties dictionary # the last ones are images labels
pd = {} # normally the difference is expected to be 0 or 1
skip = len(tag_lens) - n
if infos:
for child in infos[0]: self.labels = []
#print(child.tag+"::::::"+child.text) self.infos = []
pd[child.tag] = child.text for l in tag_lens:
string = tag_labels[0:l].replace('\x00','')
self.props = pd if skip==0:
self.labels.append(string)
# tiles are squares else:
self.tileW = int(self.props['tileWidth']) self.infos.append(string)
self.tileH = int(self.props['tileWidth']) skip -= 1
self.data_min = float(self.props['data_min']) tag_labels = tag_labels[l:]
self.data_max = float(self.props['data_max'])
# makes arrays of labels (strings) and unparsed xml infos
def __split_labels(self,n,tag):
# list
tag_lens = tag[self.__TIFF_TAG_LABELS_LENGTHS]
# string
tag_labels = tag[self.__TIFF_TAG_LABELS_STRINGS].decode()
# remove 1st element: it's something like IJIJlabl..
tag_labels = tag_labels[tag_lens[0]:]
tag_lens = tag_lens[1:]
# the last ones are images labels
# normally the difference is expected to be 0 or 1
skip = len(tag_lens) - n
self.labels = []
self.infos = []
for l in tag_lens:
string = tag_labels[0:l].replace('\x00','')
if skip==0:
self.labels.append(string)
else:
self.infos.append(string)
skip -= 1
tag_labels = tag_labels[l:]
#MAIN #MAIN
if __name__ == "__main__": if __name__ == "__main__":
try: try:
fname = sys.argv[1] fname = sys.argv[1]
except IndexError: except IndexError:
fname = "/mnt/dde6f983-d149-435e-b4a2-88749245cc6c/home/eyesis/x3d_data/data_sets/train/1527182807_896892/v02/ml/1527182807_896892-ML_DATA-08B-O-FZ0.05-OFFS0.40000.tiff" fname = "/data_ssd/lwir3d/models/002/1562390096_605721/v01/ml32/1562390096_605721-ML_DATA-32B-AOT-FZ0.03-AG.tiff"
# fname = "1521849031_093189-ML_DATA-32B-O-OFFS1.0.tiff" # fname = "/mnt/dde6f983-d149-435e-b4a2-88749245cc6c/home/eyesis/x3d_data/data_sets/train/1527182807_896892/v02/ml/1527182807_896892-ML_DATA-08B-O-FZ0.05-OFFS0.40000.tiff"
# fname = "1521849031_093189-ML_DATA-08B-O-OFFS1.0.tiff" # fname = "1521849031_093189-ML_DATA-32B-O-OFFS1.0.tiff"
# fname = "1521849031_093189-ML_DATA-08B-O-OFFS1.0.tiff"
#fname = "1521849031_093189-DISP_MAP-D0.0-46.tif"
#fname = "1526905735_662795-ML_DATA-08B-AIOTD-OFFS2.0.tiff" #fname = "1521849031_093189-DISP_MAP-D0.0-46.tif"
#fname = "test.tiff" #fname = "1526905735_662795-ML_DATA-08B-AIOTD-OFFS2.0.tiff"
#fname = "test.tiff"
print(bcolors.BOLDWHITE+"time: "+str(time.time())+bcolors.ENDC)
print(bcolors.BOLDWHITE+"time: "+str(time.time())+bcolors.ENDC)
ijt = imagej_tiff(fname)
ijt = imagej_tiff(fname)
print(bcolors.BOLDWHITE+"time: "+str(time.time())+bcolors.ENDC)
print(bcolors.BOLDWHITE+"time: "+str(time.time())+bcolors.ENDC)
print("TIFF stack labels: "+str(ijt.labels))
#print(ijt.infos) print("TIFF stack labels: "+str(ijt.labels))
#print(ijt.infos)
rough_string = ET.tostring(ijt.infos[0], "utf-8")
reparsed = minidom.parseString(rough_string) rough_string = ET.tostring(ijt.infos[0], "utf-8")
print(reparsed.toprettyxml(indent="\t")) reparsed = minidom.parseString(rough_string)
print(reparsed.toprettyxml(indent="\t"))
#print(ijt.props)
#print(ijt.props)
# needed properties:
print("Tiles shape: "+str(ijt.tileW)+"x"+str(ijt.tileH)) # needed properties:
print("Data min: "+str(ijt.data_min)) print("Tiles shape: "+str(ijt.tileW)+"x"+str(ijt.tileH))
print("Data max: "+str(ijt.data_max)) try:
print("Data min: "+str(ijt.data_min))
print(ijt.image.shape) print("Data max: "+str(ijt.data_max))
except:
# layer order: ['diagm-pair', 'diago-pair', 'hor-pairs', 'vert-pairs', 'other'] print (" No min/max are provided in 32-bit mode)")
# now split this into tiles:
print(ijt.image.shape)
#tiles = get_tile_images(ijt.image,ijt.tileW,ijt.tileH)
#print(tiles.shape) # layer order: ['diagm-pair', 'diago-pair', 'hor-pairs', 'vert-pairs', 'other']
# now split this into tiles:
tiles = ijt.getstack(['diagm-pair','diago-pair','hor-pairs','vert-pairs'],shape_as_tiles=True)
print("Stack of images shape: "+str(tiles.shape)) #tiles = get_tile_images(ijt.image,ijt.tileW,ijt.tileH)
#print(tiles.shape)
print(bcolors.BOLDWHITE+"time: "+str(time.time())+bcolors.ENDC)
# provide layer name # tiles = ijt.getstack(['diagm-pair','diago-pair','hor-pairs','vert-pairs'],shape_as_tiles=True)
values = ijt.getvalues(label='other') tiles = ijt.getstack(['diagm-aux','diago-aux','hor-aux','vert-aux'],shape_as_tiles=True)
print("Stack of values shape: "+str(values.shape)) print("Stack of images shape: "+str(tiles.shape))
# each tile's disparity: print(bcolors.BOLDWHITE+"time: "+str(time.time())+bcolors.ENDC)
# provide layer name
fig = plt.figure() values = ijt.getvalues(label='other')
fig.suptitle("Estimated Disparity") print("Stack of values shape: "+str(values.shape))
plt.imshow(values[:,:,0])
plt.colorbar() # each tile's disparity:
fig = plt.figure() fig = plt.figure()
fig.suptitle("Esitmated+Residual disparity") fig.suptitle("Estimated Disparity")
plt.imshow(values[:,:,1]) plt.imshow(values[:,:,0])
plt.colorbar() plt.colorbar()
fig = plt.figure() fig = plt.figure()
fig.suptitle("Residual disparity confidence") fig.suptitle("Esitmated+Residual disparity")
plt.imshow(values[:,:,2]) plt.imshow(values[:,:,1])
plt.colorbar() plt.colorbar()
print(bcolors.BOLDWHITE+"time: "+str(time.time())+bcolors.ENDC) fig = plt.figure()
#print(values) fig.suptitle("Residual disparity confidence")
plt.imshow(values[:,:,2])
#print(value_tiles[131,162].flatten()) plt.colorbar()
#print(np.ravel(value_tiles[131,162]))
print(bcolors.BOLDWHITE+"time: "+str(time.time())+bcolors.ENDC)
#values = np.empty((vt.shape[0],vt.shape[1],3)) #print(values)
#for i in range(values.shape[0]): #print(value_tiles[131,162].flatten())
# for j in range(values.shape[1]): #print(np.ravel(value_tiles[131,162]))
# values[i,j,0] = get_v1()
#values = np.empty((vt.shape[0],vt.shape[1],3))
#print(tiles[121,160,:,:,0].shape) #for i in range(values.shape[0]):
#_nrows = int(ijt.image.shape[0] / ijt.tileH) # for j in range(values.shape[1]):
#_ncols = int(ijt.image.shape[1] / ijt.tileW) # values[i,j,0] = get_v1()
#_nrows = 32
#_ncols = 32
#print(str(_nrows)+" "+str(_ncols)) #print(tiles[121,160,:,:,0].shape)
#fig, ax = plt.subplots(nrows=_nrows, ncols=_ncols) #_nrows = int(ijt.image.shape[0] / ijt.tileH)
#for i in range(_nrows): #_ncols = int(ijt.image.shape[1] / ijt.tileW)
# for j in range(_ncols): #_nrows = 32
# ax[i,j].imshow(tiles[i+100,j,:,:,0]) #_ncols = 32
# ax[i,j].set_axis_off() #print(str(_nrows)+" "+str(_ncols))
#fig, ax = plt.subplots(nrows=_nrows, ncols=_ncols)
#for i in range(5): #for i in range(_nrows):
# fig = plt.figure() # for j in range(_ncols):
# plt.imshow(tiles[121,160,:,:,i]) # ax[i,j].imshow(tiles[i+100,j,:,:,0])
# plt.colorbar() # ax[i,j].set_axis_off()
#ijt.show_images(['other']) #for i in range(5):
# fig = plt.figure()
#ijt.show_images([0,3]) # plt.imshow(tiles[121,160,:,:,i])
#ijt.show_images(['X-corr','Y-corr']) # plt.colorbar()
#ijt.show_images(['R-vign',3])
#ijt.show_images(['other'])
ijt.show_images()
plt.show() #ijt.show_images([0,3])
#ijt.show_images(['X-corr','Y-corr'])
#ijt.show_images(['R-vign',3])
ijt.show_images()
plt.show()
# Examples input("All done. Press ENTER to close images and exit...")
# 1: get default stack of images
#a = ijt.getstack()
#print(a.shape)
# 2: get defined ordered stack of images by tiff image index or by label name # Examples
#a = ijt.getstack([1,2,'X-corr'])
#print(a.shape) # 1: get default stack of images
#a = ijt.getstack()
# 3: will throw an error if there's no such label #print(a.shape)
#a = ijt.getstack([1,2,'Unknown'])
#print(a.shape) # 2: get defined ordered stack of images by tiff image index or by label name
#a = ijt.getstack([1,2,'X-corr'])
# 4: will throw an error if index is out of bounds #print(a.shape)
#a = ijt.getstack([1,2,'X-corr'])
#print(a.shape) # 3: will throw an error if there's no such label
#a = ijt.getstack([1,2,'Unknown'])
# 5: dev excercise #print(a.shape)
#a = np.array([[1,2],[3,4]])
#b = np.array([[5,6],[7,8]]) # 4: will throw an error if index is out of bounds
#c = np.array([[10,11],[12,13]]) #a = ijt.getstack([1,2,'X-corr'])
#print(a.shape)
#print("test1:")
#ka = (a,b,c) # 5: dev excercise
#d = np.stack(ka,axis=2) #a = np.array([[1,2],[3,4]])
#b = np.array([[5,6],[7,8]])
#print(d) #c = np.array([[10,11],[12,13]])
#print("test2:") #print("test1:")
#e = np.stack((d[:,:,1],d[:,:,0]),axis=2) #ka = (a,b,c)
#print(e) #d = np.stack(ka,axis=2)
#print(d)
#print("test2:")
#e = np.stack((d[:,:,1],d[:,:,0]),axis=2)
#print(e)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment