imagegetpixel

imagegetpixel — Return the RGB pixel values of a previously opened or created image.

Description

Return the RGB pixel values of a previously opened or created image. An image can be loaded with imageload. An empty image can be created with imagecreate.

Syntax

ared, agreen, ablue imagegetpixel iimagenum, ax, ay
kred, kgreen, kblue imagegetpixel iimagenum, kx, ky

Initialization

iimagenum -- the reference of the image.. It should be a value returned by imageload or imagecreate.

Performance

ax (kx) -- horizontal pixel position (must be a float from 0 to 1).

ay (ky) -- vertical pixel position (must be a float from 0 to 1).

ared (kred) -- red value of the pixel (mapped to a float from 0 to 1).

agreen (kgreen) -- green value of the pixel (mapped to a float from 0 to 1).

ablue (kblue) -- blue value of the pixel (mapped to a float from 0 to 1).

Examples

Here is an example of the imagegetpixel opcode. It uses the files imageopcodesdemo2.csd test1.png and test2.png.

Example 373. Example of the imagegetpixel opcode.

<CsoundSynthesizer>
<CsOptions>
; Select audio/midi flags here according to platform
; Audio out   Audio in
-odac           -iadc    ;;;RT audio I/O
; For Non-realtime ouput leave only the line below:
; -o imageopcodesdemo2.wav -W ;;; for file output any platform
</CsOptions>
<CsInstruments>
 
sr      =      	48000 
ksmps  	=     	100
nchnls	=	2

;By Cesare Marilungo 2008
zakinit 10,1

;Load the image - should be 512x512 pixels
giimage imageload "test1.png"
;giimage imageload "test2.png" ;--try this too
giimagew, giimageh imagesize giimage

giwave ftgen 1, 0, 1024, 10, 1
gifrqs ftgen 2,0,512,-5, 1,512,10
giamps ftgen 3, 0, 512, 10, 1

	instr 100

kindex = 0
icnt = giimageh
kx_ linseg 0, p3, 1
kenv linseg 0, .2, 500, p3 - .4, 500, .2, 0

; Read a column of pixels and store the red values
; inside the table 'giamps'
loop:
    ky_ = kindex/giimageh

    ;Get the pixel color values at kx_, ky_
    kred, kgreen, kblue imagegetpixel giimage, kx_, ky_

    ;Write the red values inside the table 'giamps'
    tablew kred, kindex, giamps
    kindex = kindex+1

if (kindex < icnt) kgoto loop

; Use an oscillator bank (additive synthesis) to generate sound
; setting amplitudes for each partial according to the image
asig adsynt kenv, 220, giwave, gifrqs, giamps, icnt, 2
outs asig, asig

	endin

	instr 101
; Free memory used by the image
imagefree giimage
	endin

</CsInstruments>
<CsScore>

t 0 60

i100 1 20 
i101 21 1

e

</CsScore>
</CsoundSynthesizer>


See Also

imageload, imagecreate, imagesize, imagesave, imagesetpixel, imagefree

Credits

Author: Cesare Marilungo

New in version 5.08