<commit_before>#!/bin/bash

# get real path of the binary file
rel_path_script=`dirname $0`

if [ "$3" == "" ]; then
   echo "Usage:"
   echo "  $0 im1 im2 out_disp out_mask mindisp maxdisp win P1 P2 lr"
   echo ""
   echo "  win: matched block size. It must be an odd number >=1."
   echo "  P1: The first parameter controlling the disparity smoothness."
   echo "  P2: The second parameter controlling the disparity smoothness. The"
   echo "    larger the values are, the smoother the disparity is. P1 is the penalty on"
   echo "    the disparity change by plus or minus 1 between neighbor pixels. P2 is the"
   echo "    penalty on the disparity change by more than 1 between neighbor pixels. The"
   echo "    algorithm requires P2 > P1"
   echo "  lr: max allowed difference in the left-right disparity check."
   echo ""
   echo "  Wrapper to opencv SGBM function, which implements a modified version"
   echo "  of Hirschmuller's Semi-Global Matching (SGM):"
   echo "  <NAME>. \"Stereo Processing by Semiglobal Matching and Mutual Information\""
   echo "  PAMI(30), No. 2, February 2008, pp. 328-34"
   echo "  >>> Preprocess the images computing the laplacian"
   exit 1
fi

a=$1
b=$2
disp=$3
mask=$4
im=$5
iM=$6
SAD_win=$7
P1=$8
P2=$9
lr=${10}


# convert input images to png
aa=$(basename "$a")
a_extension="${aa##*.}"
a_name="${aa%.*}"
bb=$(basename "$b")
b_extension="${bb##*.}"
b_name="${bb%.*}"
if [ $a_extension == "tif" ]; then
    thresholds=`qauto $a /tmp/$a_name.png 2>&1 |  cut -f2 -d=`
    a=/tmp/$a_name.png
    # use the same threshods for the second image
    qeasy $thresholds $b /tmp/$b_name.png
    b=/tmp/$b_name.png
fi

# HACK! make it invariant to illumination changes?
gblur 2 $a   | plambda  - " x 4 *    x(-1,0)  -1 *  +  x(1,0)  -1 * +  x(0,-1)  -1 * +    x(0,1)  -1 * + " | qauto - $a
gblur 2 $b   | plambda  - " x 4 *    x(-1,0)  -1 *  +  x(1,0)  -1 * +  x(0,-1)  -1 * +    x(0,1)  -1 * + " | qauto - $b



#usage: ./build/SGBM im1 im2 out [mindisp(0) maxdisp(64) SADwindow(1) P1(0) P2(0) LRdiff(1)]
echo "SGBM $a $b $disp $im $iM $SAD_win $P1 $P2 $lr"
SGBM $a $b $disp $im $iM $SAD_win $P1 $P2 $lr
plambda $disp "x isnan 0 255 if" | iion - $mask
<commit_msg>updated sgbm_lap wrapper<commit_after>#!/bin/bash

# get real path of the binary file
rel_path_script=`dirname $0`

if [ "$3" == "" ]; then
   echo "Usage:"
   echo "  $0 im1 im2 out_disp out_mask mindisp maxdisp win P1 P2 lr"
   echo ""
   echo "  win: matched block size. It must be an odd number >=1."
   echo "  P1: The first parameter controlling the disparity smoothness."
   echo "  P2: The second parameter controlling the disparity smoothness. The"
   echo "    larger the values are, the smoother the disparity is. P1 is the penalty on"
   echo "    the disparity change by plus or minus 1 between neighbor pixels. P2 is the"
   echo "    penalty on the disparity change by more than 1 between neighbor pixels. The"
   echo "    algorithm requires P2 > P1"
   echo "  lr: max allowed difference in the left-right disparity check."
   echo ""
   echo "  Wrapper to opencv SGBM function, which implements a modified version"
   echo "  of Hirschmuller's Semi-Global Matching (SGM):"
   echo "  <NAME>. \"Stereo Processing by Semiglobal Matching and Mutual Information\""
   echo "  PAMI(30), No. 2, February 2008, pp. 328-34"
   echo "  >>> Preprocess the images computing the laplacian"
   exit 1
fi

a=$1
b=$2
disp=$3
mask=$4
im=$5
iM=$6
SAD_win=$7
P1=$8
P2=$9
lr=${10}


# convert input images to png
aa=$(basename "$a")
a_extension="${aa##*.}"
a_name="${aa%.*}"
bb=$(basename "$b")
b_extension="${bb##*.}"
b_name="${bb%.*}"
if [ $a_extension == "tif" ]; then
    thresholds=`plambda $a "x isnan 0 x if" | qauto - $a.png 2>&1 |  cut -f2 -d=`
    a=$a.png
    # use the same threshods for the second image
    qeasy $thresholds $b $b.png
    b=$b.png
fi

# HACK! make it invariant to illumination changes?
gblur 2 $a   | plambda  - " x 4 *    x(-1,0)  -1 *  +  x(1,0)  -1 * +  x(0,-1)  -1 * +    x(0,1)  -1 * + "  -o  $a.tif
thresholds=`plambda $a.tif "x isnan 0 x if" | qauto - $a 2>&1 |  cut -f2 -d=`
gblur 2 $b   | plambda  - " x 4 *    x(-1,0)  -1 *  +  x(1,0)  -1 * +  x(0,-1)  -1 * +    x(0,1)  -1 * + " | qeasy $thresholds - $b


#usage: ./build/SGBM im1 im2 out [mindisp(0) maxdisp(64) SADwindow(1) P1(0) P2(0) LRdiff(1)]
echo "sgbm2 $a $b $disp $im $iM $SAD_win $P1 $P2 $lr"
LD_LIBRARY_PATH=/home/carlo/local/lib sgbm2 $a $b $disp $im $iM $SAD_win $P1 $P2 $lr
# the points are either unmatched or not present in the original images $1/$2, we remove these points
plambda $disp "x 0 join " | backflow - $2 | plambda $disp $1 - "x isnan y isnan z isnan or or 0 255 if" | iion - $mask

{'fraction_non_alphanumeric': 0.14769099808469888, 'fraction_numerical': 0.0417110023409236, 'mean_word_length': 3.020530367835757, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3427631', 'n_tokens_mistral': 1927, 'n_tokens_neox': 1790, 'n_words': 640}