Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Tip: Generating CSV for multi-channel histograms #275

harukizaemon started this conversation in Show and tell
Discussion options

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.

You must be logged in to vote

Replies: 5 comments 3 replies

Comment options

Nice writeup! I've made a tip label. Yup, bandunfold is supposed to make this kind of thing easy.

You must be logged in to vote
0 replies
Comment options

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
You must be logged in to vote
0 replies
Comment options

I'm using vips-8.6.4 in this image: https://hub.docker.com/r/felixbuenemann/vips-alpine

You must be logged in to vote
0 replies
Comment options

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.

You must be logged in to vote
0 replies
Comment options

Hello @Nakilon, yes, bandunfold streams the image, so you have to read and write to different files.

You must be logged in to vote
3 replies
Comment options

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.

Comment options

This discussion was originally inherited from issue #108, GitHub automatically transfers the responses as top-level.

Comment options

Oh I see. Thank you for clarification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Converted from issue

This discussion was converted from issue #108 on January 31, 2021 13:10.

AltStyle によって変換されたページ (->オリジナル) /