Image Histogram > Midi CCs

nobbystylus's picture

Hi all

Sorry my first post is a question, but i'm struggling with this.

I'm trying to create a QC patch which sends Image Histogram data from QC, splits it into RGB data, sends the separate channels out as MIDI CC information so i can kind of do video > audio control. IE the colours of my video clip control midi CCs in Live. Its for an art piece and it'd be great to enable the video to drive the filters/delays/Eqs on the music.

This is a picture of my lame attempt at the moment, and i'm getting the odd bit of data but nothing useful...

http://homepage.mac.com/bighairmusic/ableton/QCpatchHistogram.jpg

I'm using a movie loader, taking the image out of that into the image histogram patch, then splitting it (via the audio processor patch - i can't go direct into a math patch for some reason) into R, G and B, and then via a math patch to multiply the 0>1 scale i goto the midi CCs.

Any thoughts would be very appreciated as i've got a deadline pressing!

psonice's picture
I've not used histograms or

I've not used histograms or midi, but check the input and output of each patch to see if it's correct. You can quickly nail down exactly where the problem is that way.

The quickest way I find is to leave the patch running, and mouse over the in/outputs to see the value in a popup. Also select each patch in turn and look for red or orange cables - they indicate that the patch is getting the wrong kind of input.

cwright's picture
clarify + OOH

not to be a jerk, but can you clarify a little bit? What do you expect as output/what are you actually getting. What's your intended result (there may be an alternate way to accomplish what you're looking for).

Ooh: looking closer, you're attaching an image to the audio spectrum input? That's probably incorrect: the audio input expects a structure (as output by audio input I believe). that may be where the problem lies.

[Edit: just kidding, histogram outputs a structure similar to audio input, so that's ok... interesting.]

nobbystylus's picture
thanks for the reply's.. My

thanks for the reply's..

My aim is basically to turn histogram information (how much R, G, B in a video clip) into midi CC information so i can use the movement and colour data in a video to drive Midi data, tweaking plugins and effects in ableton live. The idea is a kind of reverse visualiser, where the video drives the music basically.

yes i've got rid of the audio spectrum patches and used a structure index member patch instead, which i was hoping should give me a nice clean number at the other end but it doesn't.. so i've piped that into a math patch .. but still no joy.. i'll keep going but any other thoughts would be greatly appreciated..

franz's picture
should play

this should be working. Either send your patch, or tell us what inputs you have to your math patch. Normally you should have a float. Multiplying it by 10 / 100 / something/ should provide you some results. If not, maybe your analyzed image isn't good enough (is it completly dark ?).

cwright's picture
looks like ...

I checked out the compo and poked at it a bit. Looks like he was pulling data from the histogram in regions where the video didn't provide very large values, so multiplying by 128 still didn't go above 1 (since midi data is integer stuff). I've replied to him to have him try other ranges in the histogram to see if that provides some better results.

lucretta_m's picture
adaptive scaling in javascript

If you need to guarantee that the values will be between 0 and 1 you can do an adaptive scaling patch in javascript. I haven't implemented one in QC but the basic idea would be:

(I wrote this with Tiger in mind, but the idea should work in Leopard too; just change the input and output parts)

var inputValue = inputs[0];

// optional, set to 1 to reset min and max values
var resetTrigger = inputs[1]; 

// is this how you say "or"? i think so...
// take out the | resetTrigger if you don't need it
if(Object.minValue==undefined | resetTrigger > 0) {
    Object.minValue = 10000; // really big number
    Object.maxValue = -10000; // really small number
}

var currentMin = Object.minValue;
var currentMax = Object.maxValue;

// if input is smaller then stored min change
if(inputValue < currentMin) {
  currentMin = inputValue;
  Object.minValue = currentMin;
// same with max
} else if (inputValue > currentMax) {
  currentMax = Object.maxValue;
  Object.maxValue = currentMax;
}

// rescale inputValue so that it's always within 0 and 1 of input
outputs[0] = (inputValue/(currentMax-currentMin)) + currentMin;

.... I haven't tested this code or anything, but in theory that would work. You might also want to massage the data by doing some log transforms.

Also, if you want to periodically send a reset trigger to have the scaling adapt to a different histogram be sure to add a smooth filter afterwards -- it'll jump all of a sudden

hope that helps.

nobbystylus's picture
thanks for all your

thanks for all your suggestions.. i managed to get workable results based on Christopher's input (and from David over at VDMX) and that should get me by for this project at least.. i obviously need to improve my code skills for future stuff though.. so much to learn..

blackburst's picture
histogram members

I'm trying this myself with sort of success. I can drive a midi channel with one member of the histogram structure via a structure index member, but 1/256th sample size is just too small to get pleasing results. It's too narrow a tonal range to get nice flowing cc's. I'm not too great with structures yet, so a couple of questions you might be able to help me with: do you know how I can view all the members of a structure(when i hover the mouse the popup isnt big enough)?

In this case I really need to average the members out somehow, or take the highest valued member only. Is there tools to accomplish this without having 256 structure index members patches? The aim is to have a CC that responds to "overall red", "overall green" etc and maybe a summed value for white. I also saw the image pixel patch but that too is too small a sample. Any ideas?

blackburst's picture
Re: histogram members

I ended up making this without the histogram patch. It is setup for use in vdmx as a plugin that utilises the preview windows mouse input. Adjustable sample size and cursor position. but you can replace the mouse and video input to test it out if you like. Setup for vga res but you can alter it easy enough. Any suggestions would be welcomed.

PreviewAttachmentSize
bLackburst-ColourSampler.qtz.zip7.95 KB