Moved test.sh to src, testing new filter.
This commit is contained in:
@ -301,6 +301,33 @@ class unsharp_mask_scikit(filter):
|
||||
#self.img = cv.cvtColor(self.img, cv.COLOR_RGB2GRAY)
|
||||
|
||||
|
||||
class unsharp_mask_pil(filter):
|
||||
''' Unsharp mask filter from PIL.
|
||||
|
||||
'''
|
||||
# TODO: does not work
|
||||
def __init__(self, img):
|
||||
super().__init__(img)
|
||||
|
||||
def apply(self, params):
|
||||
|
||||
# Blur radius
|
||||
radius = int(params["radius"]) if params["radius"] else 2
|
||||
|
||||
# Unsharp strength in percent
|
||||
percent = int(params["percent"]) if params["percent"] else 150
|
||||
|
||||
# Threshold controls the minimum brightness change that will be sharpened
|
||||
threshold = int(params["threshold"]) if params["threshold"] else 3
|
||||
|
||||
#print("with params: radius: " +
|
||||
# str(radius) + " percent: " + str(percent) + " threshold: " + str(threshold))
|
||||
self.img = np.uint8(self.img)
|
||||
tmp = Image.fromarray(self.img)
|
||||
tmp = tmp.filter(ImageFilter.UnsharpMask(radius, percent, threshold))
|
||||
self.img = np.asarray(tmp)
|
||||
|
||||
|
||||
class morph(filter):
|
||||
''' General morphological operations from OpenCV.
|
||||
|
||||
|
84
src/test.sh
Normal file
84
src/test.sh
Normal file
@ -0,0 +1,84 @@
|
||||
#!/bin/bash
|
||||
# test script to apply filters to all files in a directory
|
||||
# author: Rostislav Lán
|
||||
|
||||
# activate virtual environment
|
||||
source .venv/bin/activate
|
||||
|
||||
#----------------------------Settings------------------------------#
|
||||
|
||||
# place all image files to one folder
|
||||
input_path=res/test/ZK10R/p*
|
||||
exec_path=src/main.py
|
||||
|
||||
# this is very important, run this on directories containing files with the same dpi!!!!!!!!!!!!!!!!!!
|
||||
dpi=500
|
||||
|
||||
# reccomend png, it's supported by opencv
|
||||
format=png
|
||||
|
||||
# name of configuration file
|
||||
config_file=config/config-test.json
|
||||
|
||||
# name of preset in conf. file
|
||||
#presets=("strong" "test-weak" "test-repeat" "test-strong")
|
||||
presets=("test-very-strong")
|
||||
|
||||
generate_stl=false
|
||||
|
||||
#----------------------------Application---------------------------#
|
||||
|
||||
# function to apply filter to all files in directory
|
||||
apply_filter() {
|
||||
for file in ${file_arr[@]}
|
||||
do
|
||||
if test -f "$file"
|
||||
then
|
||||
in=$file
|
||||
out="${in%%${match1}*}_$preset${match1}$format"
|
||||
|
||||
# check if file already has one of the filter names in it
|
||||
#if [[ " ${presets[*]} " =~ " ${preset} " ]]; then
|
||||
# ((j++))
|
||||
# continue
|
||||
#fi
|
||||
((i++))
|
||||
echo "File no. $i: $in"
|
||||
if [[ "$generate_stl" = true ]]; then
|
||||
echo "Generating STL"
|
||||
echo $in
|
||||
python3 $exec_path $in $out $dpi -c $config_file $1 --stl "${in%%${match1}*}_$preset${match1}stl" 3 10 -p || break
|
||||
else
|
||||
python3 $exec_path $in $out $dpi -c $config_file $1 || break
|
||||
fi
|
||||
else
|
||||
echo "File $file does not exist"
|
||||
fi
|
||||
|
||||
done
|
||||
}
|
||||
|
||||
# for pattern matching in filenames
|
||||
match1=.
|
||||
match2=/
|
||||
i=0
|
||||
j=0
|
||||
file_arr=()
|
||||
|
||||
# get all filenames in all directories
|
||||
for file in $input_path/*
|
||||
do
|
||||
file_arr=("${file_arr[@]}" "$file")
|
||||
done
|
||||
|
||||
# apply all given presets to all the files
|
||||
for preset in ${presets[@]}
|
||||
do
|
||||
echo -e "\n|-----------------------Filter "$preset"------------------------------|\n"
|
||||
j=0
|
||||
apply_filter $preset $j
|
||||
if [ ! "$j" -eq "0" ]; then
|
||||
echo -e "Skipped $j files"
|
||||
fi
|
||||
done
|
||||
echo "Processed $i files"
|
Reference in New Issue
Block a user