Commit 4b0cf781 authored by Andrey Filippov's avatar Andrey Filippov

more on presentation

parent 6c88d9e2
......@@ -13,13 +13,18 @@ import sys
#import numpy as np
import imagej_tiffwriter
#import imagej_tiffwriter
import time
import imagej_tiff as ijt
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import matplotlib.colors as colors
from matplotlib.backends.backend_pdf import PdfPages
from matplotlib.ticker import (MultipleLocator, FormatStrFormatter) # AutoMinorLocator)
import qcstereo_functions as qsf
import numpy as np
......@@ -131,8 +136,12 @@ X_COLOR = "grey"
X_NEIBS = False
TRANSPARENT = True # for export
#plt.rcParams.update({'font.size': 9}) # Default = 10
plt.rcParams.update({'font.size': 10}) # Default = 10
MAJOR_Y = 2
MINOR_Y = 1
MAJOR_X = 5
MINOR_X = 1
#dbg_parameters
def get_fig_params(disparity_ranges):
......@@ -154,6 +163,7 @@ def get_fig_params(disparity_ranges):
#try:
#fig_params = get_fig_params(dbg_parameters['disparity_ranges'])
disp1_meters = dbg_parameters['disp1_meters'] # distance in meters for disparity = 1.0 # == 21.4
extra_path = os.path.join(root_dir, dbg_parameters['extra'])
eo_width = dbg_parameters['eo_params']['width']
eo_height = dbg_parameters['eo_params']['height']
......@@ -165,7 +175,22 @@ eo_woi={
"height":eo_height * eo_woi_rel['height'],
}
eo_disparity_scale = 1.0/dbg_parameters['eo_params']['disparity_scale'] # 14.2
eo_white_balance= [ #"white": [194,179,146],
255.0/dbg_parameters['eo_params']['white'][0],
255.0/dbg_parameters['eo_params']['white'][1],
255.0/dbg_parameters['eo_params']['white'][2],
]
image_sets = dbg_parameters['extra_paths'] # list of dictionaries
X_lwir=np.linspace(-0.5, IMG_WIDTH - 0.5, IMG_WIDTH + 1, endpoint=True)
Y_lwir=np.linspace(-0.5, IMG_HEIGHT - 0.5, IMG_HEIGHT + 1, endpoint=True)
X_eo=np.linspace(-0.5, eo_width - 0.5, eo_width + 1, endpoint=True)
Y_eo=np.linspace(-0.5, eo_height - 0.5, eo_height + 1, endpoint=True)
marker_shapes = ["o","D","*","s","p","p"]
marker_colors = ["r","g","b"]
marker_radius = 0.2 # map plot, will be scaled for other plots
pass
......@@ -221,11 +246,51 @@ def cross_out(
for row in range (height):
for col in range(width):
if cross_out_mask[row,col]:
xdata = [col-0.3, col+0.3]
ydata = [row-0.3, row+0.3]
xdata = [col-0.2, col+0.2]
ydata = [row-0.2, row+0.2]
plt.plot(xdata,ydata,color=X_COLOR)
ydata = [row+0.3, row-0.3]
ydata = [row+0.2, row-0.2]
plt.plot(xdata,ydata,color=X_COLOR)
def setAxisTicks(ax):
ax.xaxis.set_major_locator(MultipleLocator(MAJOR_X))
ax.xaxis.set_major_formatter(FormatStrFormatter('%d'))
ax.xaxis.set_minor_locator(MultipleLocator(MINOR_X))
ax.yaxis.set_major_locator(MultipleLocator(MAJOR_Y))
ax.yaxis.set_major_formatter(FormatStrFormatter('%d'))
ax.yaxis.set_minor_locator(MultipleLocator(MINOR_Y))
def guessMarker(src_marker):
w_eo = eo_width
h_eo = eo_height
w_lwir = IMG_WIDTH
h_lwir= IMG_HEIGHT
r=[eo_woi['x'],eo_woi['y'],eo_woi['width'],eo_woi['height']]
out_marker = [src_marker[0],src_marker[1],src_marker[2]]
if len(out_marker[0]) + len(out_marker[1]) == 0:
out_marker[1] = [8.0 * out_marker[2][0], 8.0 * out_marker[2][1]]
if len(out_marker[0]) == 0:
x = (out_marker[1][0]/w_lwir*r[2] +r[0]) * w_eo
y = (out_marker[1][1]/h_lwir*r[3] +r[1]) * h_eo
out_marker[0] = [x,y]
elif len(out_marker[1]) == 0:
x = (out_marker[0][0]/w_eo - r[0])/r[2]*w_lwir
y = (out_marker[0][1]/h_eo - r[1])/r[3]*h_lwir
if len(out_marker[2]) == 0:
x = out_marker[1][0]/8
y = out_marker[1][1]/8
out_marker[2] = [x,y]
return out_marker
def markerToString(marker):
return "eo: [%6.1f,%6.1f], lwir: [%5.1f,%5.1f], depth map: [%4.1f,%4.1f]"%(marker[0][0],marker[0][1],marker[1][0],marker[1][1],marker[2][0],marker[2][1])
'''
marker_shapes = ["o","D","*","s","p","p"]
marker_colors = ["r","g","b"]
'''
def getMarkerCode(indx):
return marker_colors[(indx//len(marker_shapes))%len(marker_colors)] + marker_shapes[indx%len(marker_shapes)]
for mode in modes: # ['train']:
figs = []
......@@ -243,13 +308,36 @@ for mode in modes: # ['train']:
if mode == 'infer':
img_file = img_file.replace('.npy','-infer.npy')
print ("Processing image set: "+img_file)
data,labels = qsf.result_npy_prepare(img_file, ABSOLUTE_DISPARITY, fix_nan=True, insert_deltas=3)
cross_out_mask = data[...,index_fgbg] < 0.5 #data.shape = (15,20,27)
# for subindex, rng in enumerate(fpars['ranges']):
markers = []
marker_codes = []
markers_dm = []
legend_eo = []
legend_lwir= []
for n, marker in enumerate (img_pars['markers']):
marker1 = guessMarker(marker)
markers.append(marker1)
gt_disp = data[marker1[2][1],marker1[2][0], qsf.GT_DISP]
nn_disp = data[marker1[2][1],marker1[2][0], qsf.NN_DISP]
gt_meters = disp1_meters/gt_disp
nn_meters = disp1_meters/nn_disp
nn_err = (nn_meters - gt_meters)/gt_meters
markers_dm.append([gt_meters, nn_meters])
marker_code = getMarkerCode(n) # markerToString()
marker_codes.append(marker_code)
legend_eo.append ("%4.1f"%(gt_meters))
legend_lwir.append("%4.1f"%(nn_meters))
s=("Marker %2d: "%(n+1))+markerToString(marker1)+(" gt:%5.1fm, nn:%5.1fm (%5f.1%%), marker:%s"%(gt_meters, nn_meters, 100*nn_err, marker_code))
print(s)
marker_radius_lwir = 8 * marker_radius
marker_radius_eo = marker_radius_lwir * eo_width/IMG_WIDTH
## marker_radius_eo_map = marker_radius_eo/8 # not used?
#disp1_meters
#marker_radius
cross_out_mask = data[...,index_fgbg] < 0.5 #data.shape = (15,20,27)
lim_val = img_pars['range'] # rng['lim_val']
lim_val[0] -= ERR_AMPL
lim_xy = [-0.5, IMG_WIDTH - 0.5, -0.5, IMG_HEIGHT - 0.5] # rng['lim_xy']
#start new image page
......@@ -257,17 +345,26 @@ for mode in modes: # ['train']:
fig.canvas.set_window_title(img_pars['title'])
fig.suptitle(img_pars['title'])
#insert LWIR JPEG image
#------------- insert LWIR JPEG image -------------
lwir_rgb = mpimg.imread(os.path.join(extra_path,img_pars['lwir_path']))
ax_lwir = plt.subplot(421)
ax_lwir.set_title("LWIR image (1 of 4)")
ax_lwir.set_title("a) LWIR image (1 of 4)")
plt.imshow(lwir_rgb)
#insert EO JPEG image
#put markers in lwir image
plt.colorbar(orientation='vertical')
if len(markers):
handles = []
for n, marker in enumerate(markers):
handles.append(plt.plot(marker[1][0], marker[1][1], marker_codes[n])[0]) # markersize= marker_radius_lwir
plt.legend(handles, legend_lwir, title = "Dist (m)", fontsize='small',bbox_to_anchor=(1.0,1), loc="upper left")
#------------- insert EO JPEG image --------------
eo_rgb = mpimg.imread(os.path.join(extra_path,img_pars['eo_path']))
# eo_rgb_wb = eo_rgb * eo_white_balance
# np.clip(eo_rgb * eo_white_balance, 0, 255)
ax_eo = plt.subplot(422)
ax_eo.set_title("Visible range image (1 of 4)")
plt.imshow(eo_rgb)
ax_eo.set_title("b) Visible range image (1 of 4)")
plt.imshow(np.clip((eo_rgb * eo_white_balance).astype(int), 0, 255))
if not eo_woi is None:
eo_woi_jpeg={
"x":eo_rgb.shape[1] * eo_woi_rel['x'],
......@@ -278,25 +375,38 @@ for mode in modes: # ['train']:
xdata=[eo_woi_jpeg['x'], eo_woi_jpeg['x'] + eo_woi_jpeg['width'], eo_woi_jpeg['x'] + eo_woi_jpeg['width'], eo_woi_jpeg['x'], eo_woi_jpeg['x']]
ydata=[eo_woi_jpeg['y'], eo_woi_jpeg['y'], eo_woi_jpeg['y'] + eo_woi_jpeg['height'], eo_woi_jpeg['y'] + eo_woi_jpeg['height'], eo_woi_jpeg['y']]
plt.plot(xdata,ydata,color=WOI_COLOR)
#put markers in eo image
plt.colorbar(orientation='vertical')
if len(markers):
handles = []
for n, marker in enumerate(markers):
handles.append(plt.plot(marker[0][0], marker[0][1], marker_codes[n])[0]) # markersize= marker_radius_eo
plt.legend(handles, legend_eo, title = "Dist (m)", fontsize='small', bbox_to_anchor=(1.0,1), loc="upper left")
# Create EO DSI image
# load tiff image
#plt.legend([red_dot, (red_dot, white_cross)], ["Attr A", "Attr A+B"])
#------------- Create EO DSI image --------------
img_ds_main = ijt.imagej_tiff(os.path.join(extra_path,img_pars['dsi_path'] ))
ds_main = img_ds_main.image[...,img_pars['dsi_slice']] * eo_disparity_scale
ds_main = np.maximum(ds_main, lim_val[0])
ds_main = np.minimum(ds_main, lim_val[1])
ax_conf=plt.subplot(424)
ax_conf.set_title("Hi-res camera disparity map")
plt.imshow(ds_main, vmin=lim_val[0], vmax=lim_val[1], cmap=cmap_disp)
ax_conf.set_title("d) Hi-res camera disparity map")
# plt.imshow(ds_main, vmin=lim_val[0], vmax=lim_val[1], cmap=cmap_disp)
setlimsxy([-0.5, eo_width-0.5, -0.5, eo_height - 0.5])
# pcm = ax_conf.pcolormesh(X_eo, Y_eo, ds_main,
pcm = ax_conf.pcolor(X_eo, Y_eo, ds_main,
norm=colors.LogNorm(vmin= lim_val[0], vmax = lim_val[1]),
cmap=cmap_disp)
ax_conf.set_aspect('equal')
if not eo_woi is None:
pass # show frame
xdata=[eo_woi['x'], eo_woi['x'] + eo_woi['width'], eo_woi['x'] + eo_woi['width'], eo_woi['x'], eo_woi['x']]
ydata=[eo_woi['y'], eo_woi['y'], eo_woi['y'] + eo_woi['height'], eo_woi['y'] + eo_woi['height'], eo_woi['y']]
plt.plot(xdata,ydata,color=WOI_COLOR)
plt.colorbar(orientation='vertical') # location='bottom')
# plt.colorbar(orientation='vertical') # location='bottom')
plt.colorbar(pcm, orientation='vertical') # location='bottom')
'''
# Ground truth confidence - to be replaced
ax_conf=plt.subplot(322)
......@@ -310,51 +420,85 @@ for mode in modes: # ['train']:
plt.colorbar(orientation='vertical') # location='bottom')
'''
#------------- Create ground truth DSI image --------------
ax_gtd=plt.subplot(423)
ax_gtd.set_title("Ground truth disparity map")
plt.imshow(data[...,qsf.GT_DISP], vmin=lim_val[0], vmax=lim_val[1], cmap=cmap_disp)
ax_gtd.set_title("c) Ground truth disparity map")
# plt.imshow(data[...,qsf.GT_DISP], vmin=lim_val[0], vmax=lim_val[1], cmap=cmap_disp)
setlimsxy(lim_xy)
cross_out(plt, cross_out_mask)
plt.colorbar(orientation='vertical') # location='bottom')
pcm = ax_gtd.pcolor(X_lwir, Y_lwir, np.minimum(np.maximum(data[..., qsf.GT_DISP],lim_val[0]),lim_val[1]),
norm=colors.LogNorm(vmin= lim_val[0], vmax = lim_val[1]),
cmap=cmap_disp)
if len(markers):
for n, marker in enumerate(markers):
plt.plot(marker[2][0], marker[2][1], marker_codes[n]) # markersize= marker_radius_lwir
ax_gtd.set_aspect('equal')
setAxisTicks(ax_gtd)
# cross_out(plt, cross_out_mask)
plt.colorbar(pcm, orientation='vertical')#
#------------- Create non-NN DSI image --------------
ax_hed=plt.subplot(425)
ax_hed.set_title("Heuristic disparity map")
plt.imshow(data[...,qsf.HEUR_NAN], vmin=lim_val[0], vmax=lim_val[1], cmap=cmap_disp)
ax_hed.set_title("e) Non-NN disparity map")
setlimsxy(lim_xy)
cross_out(plt, cross_out_mask)
plt.colorbar(orientation='vertical') # location='bottom')
pcm = ax_hed.pcolor(X_lwir, Y_lwir, np.minimum(np.maximum(data[..., qsf.HEUR_NAN],lim_val[0]),lim_val[1]),
norm=colors.LogNorm(vmin= lim_val[0], vmax = lim_val[1]),
cmap=cmap_disp)
if len(markers):
for n, marker in enumerate(markers):
plt.plot(marker[2][0], marker[2][1], marker_codes[n]) # markersize= marker_radius_lwir
ax_hed.set_aspect('equal')
setAxisTicks(ax_hed)
# cross_out(plt, cross_out_mask)
plt.colorbar(pcm, orientation='vertical')#
#------------- Create Neural network DSI image --------------
ax_nnd=plt.subplot(427)
ax_nnd.set_title("Network disparity output")
plt.imshow(data[...,qsf.NN_NAN], vmin=lim_val[0], vmax=lim_val[1], cmap=cmap_disp)
ax_nnd.set_title("g) Neural network disparity output")
setlimsxy(lim_xy)
cross_out(plt, cross_out_mask)
plt.colorbar(orientation='vertical') # location='bottom')
pcm = ax_nnd.pcolor(X_lwir, Y_lwir, np.minimum(np.maximum(data[..., qsf.NN_DISP],lim_val[0]),lim_val[1]),
norm=colors.LogNorm(vmin= lim_val[0], vmax = lim_val[1]),
cmap=cmap_disp)
if len(markers):
for n, marker in enumerate(markers):
plt.plot(marker[2][0], marker[2][1], marker_codes[n]) # markersize= marker_radius_lwir
ax_nnd.set_aspect('equal')
setAxisTicks(ax_nnd)
# cross_out(plt, cross_out_mask)
plt.colorbar(pcm, orientation='vertical')#
#------------- Create non-network DSI error --------------
ax_hee=plt.subplot(426)
ax_hee.set_title("Heuristic disparity error")
ax_hee.set_title("f) Non-NN disparity error")
cross_out(plt, cross_out_mask)
plt.imshow(data[...,qsf.HEUR_DIFF], vmin=-ERR_AMPL, vmax=ERR_AMPL, cmap=cmap_diff)
setlimsxy(lim_xy)
cross_out(plt, cross_out_mask)
if len(markers):
for n, marker in enumerate(markers):
plt.plot(marker[2][0], marker[2][1], marker_codes[n]) # markersize= marker_radius_lwir
setAxisTicks(ax_hee)
plt.colorbar(orientation='vertical') # location='bottom')
#------------- Create neural network DSI error --------------
ax_nne=plt.subplot(428)
ax_nne.set_title("Network disparity error")
ax_nne.set_title("h) Neural network disparity error")
plt.imshow(data[...,qsf.NN_DIFF], vmin=-ERR_AMPL, vmax=ERR_AMPL, cmap=cmap_diff)
setlimsxy(lim_xy)
cross_out(plt, cross_out_mask)
if len(markers):
for n, marker in enumerate(markers):
plt.plot(marker[2][0], marker[2][1], marker_codes[n]) # markersize= marker_radius_lwir
setAxisTicks(ax_nne)
plt.colorbar(orientation='vertical') # location='bottom')
plt.tight_layout(rect =[0,0,1,TIGHT_TOP], h_pad = TIGHT_HPAD, w_pad = TIGHT_WPAD)
figs.append(fig)
fb_noext = os.path.splitext(os.path.basename(img_file))[0]#
# if subindex > 0:
# if subindex < 10:
# fb_noext+="abcdefghi"[subindex-1]
# else:
# fb_noext+="-"+str(subindex)
ffiles.append(fb_noext)
pass
......
......@@ -751,7 +751,7 @@ def result_npy_prepare(npy_path, absolute, fix_nan, insert_deltas=True,labels=No
weight9 *= w8
w_center = np.sum(weight9, axis=2)
dw_center = np.sum(data9*weight9, axis=2)
dw_center /= w_center # now dw_center - weighted average in the center
dw_center /= w_center # now dw_center - weighted average in the center invalid /
data[...,-3] = np.abs(data[...,GT_DISP]- dw_center)
......
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