First of all, make sure the following requirements are installed on your system:
To find more building and running options take a look at the MiniScaffold template.
Go to directory with your build.fsproj
(or build.csproj
) file and install ImageProcessing using command line:
|
For more information visit package main GitHub page.
The following features are implemented, even for CPU and GPU:
For detailed descriptions of all features above visit Api Reference.
Before usage, go to specify directory:
|
To process images from one directory and save them to another, you can use the following commands.
|
|
You can find more details about CLI processing here.
Open library and load image to process:
open MyImage
open CPU
open GPU
let myImage = load ("Full/Path/To/Images/Folder/image_name.jpg")
Create new function which sequentially applies blur filter and clockwise rotation to images and saves it on CPU:
let applyCustomFilterOnCPU (image: MyImage) (pathToSave : string) =
let blurredImage = image |> applyFilter gaussianBlurKernel
let rotatedImage = blurredImage |> rotate true
MyImage.save rotatedImage pathToSave
Create the same function for GPU. But before it we need to do some steps for diagnosing graphical device.
Define the device
value by specifying the brand of your GPU or whatever the program finds (embedded graphics cards are also suitable). And make OpenCL context of it:
let device = Brahma.FSharp.ClDevice.GetFirstAppropriateDevice()
let clContext = Brahma.FSharp.ClContext(device)
Next, define new values for filter and rotation functions. This action is necessary because of compiling kernel function once:
let applyFilterGPU = applyFilter clContext 64
let rotateGPU = rotate clContext 64
And the final function:
let applyCustomFilterOnGPU (image: MyImage) (pathToSave : string) =
let blurredImage = image |> applyFilterGPU gaussianBlurKernel
let rotatedImage = blurredImage |> rotateGPU true
MyImage.save rotatedImage pathToSave
The result:
open MyImage
open CPU
open GPU
let myImage = load ("Full/Path/To/Images/Folder/image_name.jpg")
let applyCustomFilterOnCPU (image: MyImage) (pathToSave : string) =
let blurredImage = image |> applyFilter gaussianBlurKernel
let rotatedImage = blurredImage |> rotate true
MyImage.save rotatedImage pathToSave
let device = Brahma.FSharp.ClDevice.GetFirstAppropriateDevice()
let clContext = Brahma.FSharp.ClContext(device)
let applyFilterGPU = applyFilter clContext 64
let rotateGPU = rotate clContext 64
let applyCustomFilterOnGPU (image: MyImage) (pathToSave : string) =
let blurredImage = image |> applyFilterGPU gaussianBlurKernel
let rotatedImage = blurredImage |> rotateGPU true
MyImage.save rotatedImage pathToSave
let pathToSave = "Path/To/Directory/image_name.jpg"
applyCustomFilterOnCPU myImage pathToSave
applyCustomFilterOnGPU myImage pathToSave