-
Notifications
You must be signed in to change notification settings - Fork 62
Tip: Generating CSV for multi-channel histograms #275
-
I wanted to generate a histogram as a CSV file for single and multi-channel images. The format I needed was each row represents an intensity, each column represents a channel. This differs from the standard VIPS histogram which is a single row with a column for each intensity value for a single channel only.
My initial approach was to take the histogram and iterate over each element of the histogram which worked great on RGBA (about 4.5 seconds) but for a 2-byte greyscale image, this took about 5 minutes.
The following runs in about 0.07 seconds for RGBA and about 5 seconds for the ushort:
image .hist_find .rot90 .bandunfold .csvsave("histogram.csv", separator: ",")
There may well be a better way, but that worked for me :)
Oh, the only other thing I wish I could do is add column headers but I can live without them.
Beta Was this translation helpful? Give feedback.
All reactions
-
❤️ 1
Replies: 5 comments 3 replies
-
Nice writeup! I've made a tip
label. Yup, bandunfold
is supposed to make this kind of thing easy.
Beta Was this translation helpful? Give feedback.
All reactions
-
I have a problem using this bandunfold
operation in shell.
vips crop $filepath_file temp.v $v_left $v_top $v_width $v_height && vips csvsave temp.v temp.csv && cat temp.csv
104 103 103 103
104 103 103 103
104 103 103 103
104 104 103 103
105 105 104 104
vips crop $filepath_file temp.v $v_left $v_top $v_width $v_height && vips bandunfold temp.v temp.v --factor 3 && vips csvsave temp.v temp.csv && cat temp.csv
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0
It gives me all zeros.
$ file $filepath_file
.../house.png: PNG image data, 120 x 162, 8-bit/color RGB, non-interlaced
Beta Was this translation helpful? Give feedback.
All reactions
-
I'm using vips-8.6.4 in this image: https://hub.docker.com/r/felixbuenemann/vips-alpine
Beta Was this translation helpful? Give feedback.
All reactions
-
Oh I made vips bandunfold temp.v temp_.v --factor 3 && vips csvsave temp_.v temp.csv
and now it works. Seems like the bandunfold
operation does not support the same filename as in
and out
.
Beta Was this translation helpful? Give feedback.
All reactions
-
Hello @Nakilon, yes, bandunfold
streams the image, so you have to read and write to different files.
Beta Was this translation helpful? Give feedback.
All reactions
-
Lol I just realised I was confused by the ugly Github interface and all my comments went as top level replies but were intended to reply to your subthread. Probably not the first time I did that.
Beta Was this translation helpful? Give feedback.
All reactions
-
This discussion was originally inherited from issue #108, GitHub automatically transfers the responses as top-level.
Beta Was this translation helpful? Give feedback.
All reactions
-
Oh I see. Thank you for clarification.
Beta Was this translation helpful? Give feedback.