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,6 +55,50 @@ class bcolors:
BOLD = '\033[1m'
BOLDWHITE = '\033[1;37m'
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
def get_tile_images(image, width=8, height=8):
......@@ -95,7 +139,6 @@ Examples:
'''
class imagej_tiff:
# imagej stores labels lengths in this tag
__TIFF_TAG_LABELS_LENGTHS = 50838
# imagej stores labels conents in this tag
......@@ -133,9 +176,7 @@ class imagej_tiff:
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:
......@@ -151,7 +192,7 @@ class imagej_tiff:
a[a==0]=np.nan
a = a.astype(float)
if self.labels[i]!='other':
# a[a==0]=np.nan
# a[a==0]=np.nan
a = (_max-_min)*(a-_MIN)/(_MAX-_MIN)+_min
# init
if i==0:
......@@ -171,24 +212,24 @@ class imagej_tiff:
indx += 1
else:
other_label = "other"
# print(tile_list)
# print(tile_list)
num_tiles = len(tile_list)
num_layers = len(layers)
tiles_corr = np.empty((num_tiles,num_layers,self.tileH*self.tileW),dtype=float)
# tiles_other=np.empty((num_tiles,3),dtype=float)
tiles_other=self.gettilesvalues(
# tiles_other=np.empty((num_tiles,3),dtype=float)
tiles_other=self.gettilesvalues( # returns nparray of 11 floats (was 3)
tif = tif,
tile_list=tile_list,
label=other_label)
for nl,label in enumerate(layers):
tif.seek(self.labels.index(label))
tif.seek(self.labels.index(label)) #'hor-pairs' is not in list
layer = np.array(tif) # 8 or 32 bits
tilesX = layer.shape[1]//self.tileW
for nt,tl in enumerate(tile_list):
ty = tl // tilesX
tx = tl % tilesX
# tiles_corr[nt,nl] = np.ravel(layer[self.tileH*ty:self.tileH*(ty+1),self.tileW*tx:self.tileW*(tx+1)])
a = np.ravel(layer[self.tileH*ty:self.tileH*(ty+1),self.tileW*tx:self.tileW*(tx+1)])
a = np.ravel(layer[self.tileH * ty : self.tileH * (ty+1),
self.tileW * tx : self.tileW * (tx+1)])
#convert from int8
if self.bpp==8:
a = a.astype(float)
......@@ -212,6 +253,7 @@ class imagej_tiff:
self.corr2d = tiles_corr
self.target_disparity = tiles_other[...,0]
self.gt_ds = tiles_other[...,1:3]
self.payload = tiles_other#[...,0:12]
pass
# init done, close the image
......@@ -220,26 +262,29 @@ class imagej_tiff:
# 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))
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:
res[i,j,0] = m[0]
res[i,j,1] = m[2]
res[i,j,2] = m[4]
for k in range(res.shape[2]):
res[i,j,k] = m[k * 2]
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
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:
res[i,j,0] = np.nan
res[i,j,1] = np.nan
res[i,j,2] = np.nan
for k in range(res.shape[2]):
res[i,j,k] = np.nan
# NaNize
# NaNize - TODO: update !
if self.bpp==8:
a = res[:,:,0]
a[a==-256] = np.nan
b = res[:,:,1]
......@@ -249,11 +294,12 @@ class imagej_tiff:
return res
# 3 values per tile: target disparity, GT disparity, GT confidence
# With LWIR/aux there are more!
def gettilesvalues(self,
tif,
tile_list,
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))
layer = np.array(tif) # 8 or 32 bits
tilesX = layer.shape[1]//self.tileW
......@@ -262,30 +308,29 @@ class imagej_tiff:
tx = tl % tilesX
m = np.ravel(layer[self.tileH*ty:self.tileH*(ty+1),self.tileW*tx:self.tileW*(tx+1)])
if self.bpp==32:
res[i,0] = m[0]
res[i,1] = m[2]
res[i,2] = m[4]
for k in range(res.shape[1]):
res[i,k] = m[k * 2]
elif self.bpp==8:
res[i,0] = ((m[0]-128)*256+m[1])/128
res[i,1] = ((m[2]-128)*256+m[3])/128
res[i,2] = (m[4]*256+m[5])/65536.0
for k in range(res.shape[1]):
if k in IJML.SIGNED:
res[i,k] = ((m[2 * k] - 128) * 256 + m[2 * k + 1]) / 128
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:
res[i,0] = np.nan
res[i,1] = np.nan
res[i,2] = np.nan
# NaNize
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):
......@@ -308,14 +353,13 @@ class imagej_tiff:
return b
# get np.array of a channel
# * do not handle out of bounds
# * does not handle out of bounds
def channel(self,index):
return self.image[:,:,index]
# display images by index or label
def show_images(self,items=[]):
# show listed only
if len(items)>0:
for i in items:
......@@ -332,9 +376,7 @@ class imagej_tiff:
# display single image
def show_image(self,index):
# display using matplotlib
t = self.image[:,:,index]
mytitle = "("+str(index+1)+" of "+str(self.nimages)+") "+self.labels[index]
fig = plt.figure()
......@@ -355,7 +397,6 @@ class imagej_tiff:
# puts etrees in infoss
def __parse_info(self):
infos = []
for info in self.infos:
infos.append(ET.fromstring(info))
......@@ -376,12 +417,12 @@ class imagej_tiff:
# tiles are squares
self.tileW = int(self.props['tileWidth'])
self.tileH = int(self.props['tileWidth'])
if self.bpp==8:
self.data_min = float(self.props['data_min'])
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
......@@ -412,9 +453,10 @@ if __name__ == "__main__":
try:
fname = sys.argv[1]
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 = "1521849031_093189-ML_DATA-32B-O-OFFS1.0.tiff"
# fname = "1521849031_093189-ML_DATA-08B-O-OFFS1.0.tiff"
fname = "/data_ssd/lwir3d/models/002/1562390096_605721/v01/ml32/1562390096_605721-ML_DATA-32B-AOT-FZ0.03-AG.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-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"
......@@ -437,8 +479,11 @@ if __name__ == "__main__":
# needed properties:
print("Tiles shape: "+str(ijt.tileW)+"x"+str(ijt.tileH))
try:
print("Data min: "+str(ijt.data_min))
print("Data max: "+str(ijt.data_max))
except:
print (" No min/max are provided in 32-bit mode)")
print(ijt.image.shape)
......@@ -448,7 +493,8 @@ if __name__ == "__main__":
#tiles = get_tile_images(ijt.image,ijt.tileW,ijt.tileH)
#print(tiles.shape)
tiles = ijt.getstack(['diagm-pair','diago-pair','hor-pairs','vert-pairs'],shape_as_tiles=True)
# tiles = ijt.getstack(['diagm-pair','diago-pair','hor-pairs','vert-pairs'],shape_as_tiles=True)
tiles = ijt.getstack(['diagm-aux','diago-aux','hor-aux','vert-aux'],shape_as_tiles=True)
print("Stack of images shape: "+str(tiles.shape))
print(bcolors.BOLDWHITE+"time: "+str(time.time())+bcolors.ENDC)
......@@ -511,6 +557,7 @@ if __name__ == "__main__":
ijt.show_images()
plt.show()
input("All done. Press ENTER to close images and exit...")
......
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