vendredi 21 avril 2017

RedCV: Split channels

This example introduces RedCV basic fonctions

rcvCreateImage

Creates and returns empty (black) image. Function parameter is the image size as a pair!

rcvLoadImage


Loads image from file. Function parameter is name of the file to load as a Red file! datatype. By default, images are loaded as RGB images. Function can use /grayscale refinement in order to force the image to be loaded as a grayscale image. In this case simply use img: rcvLoadImage/grayscale %file name.

rcvSplit


Separates source image in RGBA channels. Function parameters are the source and the destination images. Destination image contains the selected source channel. /red /green /blue /alpha refinements are used to selected the colour channel.

Code example

Red [
    Title: "Channel tests "
    Author: "Francois Jouen"
    File:    %SplitChannels.red
    Needs:   'View
]
; last Red Master required!
#include %../../libs/redcv.red ; for redCV functions
margins: 10x10
img1: rcvLoadImage %../../images/baboon.jpg
dst: rcvCreateImage img1/size

; ***************** Test Program ****************************
view win: layout [
        title "RGB Channels Test"
        origin margins space margins
        button 80 "Source"  [_rcvChannel img1 dst 0]    ; routine
        button 70 "Red"    [rcvSplit/red img1 dst]
        button 70 "Green"   [rcvSplit/green img1 dst]
        button 70 "Blue"   [rcvSplit/blue img1 dst]
        button 70 "Alpha"  [rcvSplit/alpha img1 dst]
        button 80 "Quit"    [rcvReleaseImage img1 rcvReleaseImage dst Quit]
        return
        canvas: base 512x512 dst    
        do [_rcvChannel img1 dst 0]
]

And the result for the blue channel 




Aucun commentaire:

Enregistrer un commentaire