Skip to content
Snippets Groups Projects
Commit a89ae740 authored by Toke Eskildsen's avatar Toke Eskildsen
Browse files

Closes #46 (The histogram values sometimes contain colormap data)

parent a8465ea4
No related branches found
No related tags found
No related merge requests found
...@@ -66,6 +66,19 @@ function im_identify() { ...@@ -66,6 +66,19 @@ function im_identify() {
} }
export -f im_identify export -f im_identify
# Outputs all the greyscale values and their counts
# Input: Image [destination]
function greys() {
local IFILE=`im_identify "$1" "$2"`
local VALUES=`cat "$IDENTIFY" | grep -A 256 Histogram`
if [ ! "." == ".`grep Colormap "$IFILE"`" ]; then
cat "$IFILE" | grep -A 257 Histogram | grep -B 256 Colormap | grep "[0-9]\\+: ("
else
cat "$IFILE" | grep -A 256 Histogram | grep "[0-9]\\+: ("
fi
}
export -f greys
# TODO: Accept destination for grey-stats-file as input # TODO: Accept destination for grey-stats-file as input
...@@ -92,15 +105,16 @@ function grey_stats() { ...@@ -92,15 +105,16 @@ function grey_stats() {
local GREY=${DEST_FOLDER}/${BASE%%.*}.grey local GREY=${DEST_FOLDER}/${BASE%%.*}.grey
local INFO=`cat "$IDENTIFY"` local INFO=`cat "$IDENTIFY"`
local RAW_VALUES=`greys "$SRC" "$DEST_FOLDER"`
# TODO: No good as the histogram data might be much less than 256 # TODO: No good as the histogram data might be much less than 256
local VALUES=`cat "$IDENTIFY" | grep -A 256 Histogram` # local VALUES=`cat "$IDENTIFY" | grep -A 256 Histogram`
if [ ! "." == ".`echo "$VALUES" | grep Colormap`" ]; then # if [ ! "." == ".`echo "$VALUES" | grep Colormap`" ]; then
local VALUES=`echo "$VALUES" | grep -B 256 Colormap` # local VALUES=`echo "$VALUES" | grep -B 256 Colormap`
fi # fi
local RAW_VALUES=`echo "$VALUES" | grep "[0-9]\\+: ("` # local RAW_VALUES=`echo "$VALUES" | grep "[0-9]\\+: ("`
# local VALUES="$INFO" # local VALUES="$INFO"
# ***
local SAVEIFS=$IFS # local SAVEIFS=$IFS
IFS=$(echo -en $"\n") IFS=$(echo -en $"\n")
local UNIQUE=`echo "$RAW_VALUES" | wc -l` local UNIQUE=`echo "$RAW_VALUES" | wc -l`
...@@ -203,11 +217,7 @@ function histogramScript() { ...@@ -203,11 +217,7 @@ function histogramScript() {
# into # into
# 0 78085 # 0 78085
# 1 3410 # 1 3410
if [ "." == ".`grep \"Colormap:\" \"$IDENTIFY\"`" ]; then GREYS=`greys "$SRC" | sed 's/ \\+\\([0-9]\\+\\): ( *\\([0-9]\\+\\).\\+/\\2 \\1/g'`
GREYS=`cat "$IDENTIFY" | grep -A 256 " Histogram:" | grep -o " \\+[0-9]\\+: ( *[0-9]\\+, *[0-9]\\+, *[0-9]\\+)" | sed 's/ \\+\\([0-9]\\+\\): ( *\\([0-9]\\+\\).\\+/\\2 \\1/g'`
else
GREYS=`cat "$IDENTIFY" | grep -A 9999 " Histogram:" | grep -B 256 "Colormap:" | grep -o " \\+[0-9]\\+: ( *[0-9]\\+, *[0-9]\\+, *[0-9]\\+)" | sed 's/ \\+\\([0-9]\\+\\): ( *\\([0-9]\\+\\).\\+/\\2 \\1/g'`
fi
# Find lowest and highest for both intensity and count # Find lowest and highest for both intensity and count
local MIN_GREY=255 local MIN_GREY=255
local MAX_GREY=0 local MAX_GREY=0
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment