Search code examples
imagemagickgnuplotimage-manipulation

Palette Mapped Surface view or Heat Map help n GNUPLOT


I have a data set of average RGB values derived from an image. The image is 1729 x 981 and I've used imagemagick to average each 170x98 pixel section and output a CSV with the data. this gives me 153 lines representing the 17 sections across and 9 down.

What I'm trying to achieve, and failing at, is creating basically a heat map, or pallet mapped surface view of the image with the average data shown across the 17 x 9 sections using GNUPLOT.

My assumption is that my data is formatted incorrectly. But I also know very little about gnupolot. So there's that.

Here is the data set I'm using.
https://www.dropbox.com/s/1mfhgkrdbo5xdrj/RNST_SDI_20220303_145749.DPX_DATA.csv?dl=0

Any help is greatly appreciated.


Solution

  • I will rephrase my comment as a preliminary answer.

    The form of the command you want is plot DATA using x:y:R:G:B with rgbimage but it is not entirely clear from your description how to derive the R/G/B components. The range of values in columns 2/3/4 of the file you linked to contain values roughly in the range 450 - 550. Usually the color components either run from 0.0 - 1.0 or from 0 - 255. For the purpose of illustration I will convert yours into numbers in the range 0.0-1.0 and show the plot command.

    We will derive the x and y components from the line number, ignore the content of column 1, and scale columns 2/3/4 to the range 0-1. You don't say how you want the result marked up with pixel coordinates, titles, or the like so I just leave everything to default.

     set datafile separator comma       # it's a csv file
     set rgbmax 1.0                     # color components in the range 0-1
     conv(C) = (column(C)-450.)/100. 
     plot 'DPX_DATA.csv' using (int($0)%17) : (int($0)/17) : (conv(2)) : (conv(3)) : (conv(4)) with rgbimage
    

    enter image description here

    Expanded answer

    There are several ways to pass additional parameters into gnuplot from the command line. Unfortunately I am not conversant with bash scripting so I can't help with construction of the command line as you show it in your comment. What I can do is show how to read an environmental variable NAME from inside gnuplot:

    name = system("printenv NAME")
    infile = name . ".csv"
    outfile = name . "_RGB_AVGs.png"
    set term png
    set output outfile
    plot infile using ... with rgbimage