Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Tip: Generating CSV for multi-channel histograms #108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
harukizaemon opened this issue Apr 27, 2017 · 5 comments
Closed

Tip: Generating CSV for multi-channel histograms #108

harukizaemon opened this issue Apr 27, 2017 · 5 comments
Labels

Comments

@harukizaemon
Copy link

harukizaemon commented Apr 27, 2017

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.

@jcupitt jcupitt added the tip label Apr 27, 2017
@jcupitt
Copy link
Member

jcupitt commented Apr 27, 2017

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

@Nakilon
Copy link
Contributor

Nakilon commented Feb 28, 2019

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

@Nakilon
Copy link
Contributor

Nakilon commented Feb 28, 2019

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

@Nakilon
Copy link
Contributor

Nakilon commented Feb 28, 2019

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.

@jcupitt
Copy link
Member

jcupitt commented Feb 28, 2019

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

@jcupitt jcupitt closed this as completed Jan 31, 2021
@libvips libvips locked and limited conversation to collaborators Jan 31, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
Projects
None yet
Development

No branches or pull requests

3 participants