close all
clear

file_name = 'data/InterHand/residuals.json';
fid = fopen(file_name);
raw = fread(fid, inf);
fclose(fid);

values = jsondecode(char(raw'));

joints_2d = values.joints_2d(:, 1) * 256;
joints_depth = values.joints_depth(:, 1);
depth = values.depth(:, 1);

mean_j_2d = mean(joints_2d);
std_j_2d = std(joints_2d);
mean_j_depth = mean(joints_depth);
std_j_depth = std(joints_depth);
mean_depth = mean(depth);
std_depth = std(depth);

figure()
subplot(1, 3, 1)
histogram(joints_2d, 10^4, 'BinLimits', [mean_j_2d-3*std_j_2d, mean_j_2d+3*std_j_2d], 'Normalization', 'probability')
title(sprintf('2D Joints %.2f±%.2f', mean_j_2d, std_j_2d))
subplot(1, 3, 2)
histogram(joints_2d, 10^4, 'BinLimits', [mean_j_depth-3*std_j_depth, mean_j_depth+3*std_j_depth], 'Normalization', 'probability')
title(sprintf('Depth Joints %.2f±%.2f', mean_j_depth, std_j_depth))
subplot(1, 3, 3)
histogram(joints_2d, 10^4, 'BinLimits', [mean_depth-3*std_depth, mean_depth+3*std_depth], 'Normalization', 'probability')
title(sprintf('Relative Depth %.2f±%.2f', mean_depth, std_depth))
