read rgb values into matrix
I have an rgb file in following format:
A=,255, R=,65, G=,181, B=,80
A=,255, R=,12, G=,130, B=,18
I am not interested in the opacity (A) value.
I am new to max for live. I would like to get those values I am assuming into a jitter matrix, then have another pre "programed" matrix that will tell me what to do when i encounter a certain values.
I have looked at the documentation help on jit.textfile but not succeeding in getting the file in.
I have shrunk the file ie a short version but the rgb values are from an image so i might need to read them in frame at a time.
I cannot determine how to put in the read part and neither to tell jit.textfile the filename as opposed to browser.
would appreciate a hint for this.
regards in advance
I can read the file now and put into a matrix, how do i read a very large file bit by bit?
so presumably each line represents the argb char values of a single pixel: do you know the dimensions of the matrix? do you know how each line corresponds to each pixel in the matrix?
what you need to do is convert each line of text into those corresponding byte values, so you need to parse the text file somehow
you could use the text (forget about jit.textfile) object to read in the text file then read each line one by one into some sort of parsing sub-patch (maybe using regexp) to create 4-element lists which can then be assigned to their corresponding pixel in a matrix (using setcell messages)
I suspect you need to do more reading up about what various objects in max do
hope this helps anyway
heres one way of parsing your text using route (may not apply if message box not used)
The length of the text file i want to read in will change so the width of the array will always be same but the depth will always vary dependant on the photo. As you have said i think i need to take in line by line as a jpg file has lots of rows of info but yes you have described the process. I was hoping i might be able to get the total values grouped into "colours of the rainbow" thatll allow me more or less to cover a scale. First have to get through the learning curve. Ok i will try what you said. Most of the examples cover movie files but I just want to read the data from a photo.
Thx so far
so you want to sort the colours? to create a histogram? why does the photo need to be converted to a text file? why don't you read the photo in directly into jitter? there's an object (I think) called jit.bubblesort which can sort values in ascending order (although I don't think it would preserve rgb relations)
Its difficult for me to explain. I break it down to small step.
1. I want to read rgb values from a photo.
2. Read the "flavour" of the colours. Getting a grouping of the colours like a histogram might allow me to decide on a scale.
3. turn the rgb values into note values dependant on their value. (here i was thinking about rainbow colours and mapping them to a scale.
4. for Tempo I thought I would just set the tempo manually and maybe read the rgb values in according to the tempo set in ableton.
hope that explains a little better.
aha a penny has clicked here on something you said. As part of the process I used:
http://itg.beckman.illinois.edu/technology_development/software_development/get_rgb/
that program to convert the image to a list of its rgb values but if you say I dont need to do that then that would be great. I am not sure what the effect would be of not reading the rgb values and conversion to note value if sorted. I think they definitely need to be read as they are in the same as the sequence of pixel values.
Like Floating Point said, its a lot easier to do everything within Max.
The following code should give you a good starting point, it takes an image in and use the color values to generate an audio signal. The next step for you would be to do some analysis or processing on the image prior to sending it to audio.
I think you really need to go through the jitter tutorials-- once a photo is imported into a matrix it IS in rgb values. already. that is what a jitter matrix is, a set of 2D arrays of values, one 2D plane for each representation of a, r, g and b
how you place those r, g and b values onto some sort of perceptual colour-scale is another thing-- you may want to convert them to L*a*b* colour-space and see where the colours lie along the a and b axes (discard L); then you could categorise them according to 'warmness' and 'coolness'
Thank you so much its given me a great place to start.
Hey did you ever figure this out @PB21? I am trying to do the same thing you are
No other things took over and I never carried on with it. :(