Example: Using MBrace for image processing
This tutorial is from the MBrace Starter Kit.
In this tutorial, you use the AForge (you can install AForge from Nuget) to turn color images into gray ones by applying a gray filter.
1: 2: 3: 4: 5: 6: 7: 8: |
|
Next, you define a method to download an image from a url, and return a stream containing the downloaded image.
1: 2: 3: 4: 5: |
|
Next, you create a method that turns the downloaded color image into a gray image by applying an AForge filter, and then uploads the gray image to cloud storage.
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: |
|
Last, you perform parallel downloading and image processing in the MBrace cluster.
1: 2: 3: 4: 5: 6: 7: 8: |
|
The results are a set of cloud storage file paths for the generated images. You can look these up in your cloud storage account browser.
1: 2: |
|
In this tutorial, you've learned how to use the AForge image processing library to turn color images to gray ones in MBrace. Continue with further samples to learn more about the MBrace programming model.
Note, you can use the above techniques from both scripts and compiled projects. To see the components referenced by this script, see ThespianCluster.fsx or AzureCluster.fsx.
Full name: 200-image-processing-example.cluster
Full name: Config.GetCluster
Gets or creates a new Thespian cluster session.
Full name: 200-image-processing-example.GetStreamFromUrl
val string : value:'T -> string
Full name: Microsoft.FSharp.Core.Operators.string
--------------------
type string = String
Full name: Microsoft.FSharp.Core.string
type WebClient =
inherit Component
new : unit -> WebClient
member BaseAddress : string with get, set
member CachePolicy : RequestCachePolicy with get, set
member CancelAsync : unit -> unit
member Credentials : ICredentials with get, set
member DownloadData : address:string -> byte[] + 1 overload
member DownloadDataAsync : address:Uri -> unit + 1 overload
member DownloadFile : address:string * fileName:string -> unit + 1 overload
member DownloadFileAsync : address:Uri * fileName:string -> unit + 1 overload
member DownloadString : address:string -> string + 1 overload
...
Full name: System.Net.WebClient
--------------------
WebClient() : unit
WebClient.DownloadData(address: string) : byte []
type MemoryStream =
inherit Stream
new : unit -> MemoryStream + 6 overloads
member CanRead : bool
member CanSeek : bool
member CanWrite : bool
member Capacity : int with get, set
member Flush : unit -> unit
member GetBuffer : unit -> byte[]
member Length : int64
member Position : int64 with get, set
member Read : buffer:byte[] * offset:int * count:int -> int
...
Full name: System.IO.MemoryStream
--------------------
MemoryStream() : unit
MemoryStream(capacity: int) : unit
MemoryStream(buffer: byte []) : unit
MemoryStream(buffer: byte [], writable: bool) : unit
MemoryStream(buffer: byte [], index: int, count: int) : unit
MemoryStream(buffer: byte [], index: int, count: int, writable: bool) : unit
MemoryStream(buffer: byte [], index: int, count: int, writable: bool, publiclyVisible: bool) : unit
Full name: 200-image-processing-example.GrayImageFromWeb
type Bitmap =
inherit Image
new : filename:string -> Bitmap + 11 overloads
member Clone : rect:Rectangle * format:PixelFormat -> Bitmap + 1 overload
member GetHbitmap : unit -> nativeint + 1 overload
member GetHicon : unit -> nativeint
member GetPixel : x:int * y:int -> Color
member LockBits : rect:Rectangle * flags:ImageLockMode * format:PixelFormat -> BitmapData + 1 overload
member MakeTransparent : unit -> unit + 1 overload
member SetPixel : x:int * y:int * color:Color -> unit
member SetResolution : xDpi:float32 * yDpi:float32 -> unit
member UnlockBits : bitmapdata:BitmapData -> unit
...
Full name: System.Drawing.Bitmap
--------------------
Bitmap(filename: string) : unit
(+0 other overloads)
Bitmap(stream: Stream) : unit
(+0 other overloads)
Bitmap(original: Image) : unit
(+0 other overloads)
Bitmap(filename: string, useIcm: bool) : unit
(+0 other overloads)
Bitmap(type: Type, resource: string) : unit
(+0 other overloads)
Bitmap(stream: Stream, useIcm: bool) : unit
(+0 other overloads)
Bitmap(width: int, height: int) : unit
(+0 other overloads)
Bitmap(original: Image, newSize: Size) : unit
(+0 other overloads)
Bitmap(width: int, height: int, format: Imaging.PixelFormat) : unit
(+0 other overloads)
Bitmap(width: int, height: int, g: Graphics) : unit
(+0 other overloads)
type Grayscale =
inherit BaseFilter
new : cr:float * cg:float * cb:float -> Grayscale
val RedCoefficient : float
val GreenCoefficient : float
val BlueCoefficient : float
member FormatTranslations : Dictionary<PixelFormat, PixelFormat>
nested type CommonAlgorithms
Full name: AForge.Imaging.Filters.Grayscale
--------------------
Grayscale(cr: float, cg: float, cb: float) : unit
static val BT709 : Grayscale
static val RMY : Grayscale
static val Y : Grayscale
Full name: AForge.Imaging.Filters.Grayscale.CommonAlgorithms
BaseFilter.Apply(imageData: Imaging.BitmapData) : Bitmap
BaseFilter.Apply(image: Bitmap) : Bitmap
BaseFilter.Apply(sourceImage: AForge.Imaging.UnmanagedImage, destinationImage: AForge.Imaging.UnmanagedImage) : unit
type ImageFormat =
new : guid:Guid -> ImageFormat
member Equals : o:obj -> bool
member GetHashCode : unit -> int
member Guid : Guid
member ToString : unit -> string
static member Bmp : ImageFormat
static member Emf : ImageFormat
static member Exif : ImageFormat
static member Gif : ImageFormat
static member Icon : ImageFormat
...
Full name: System.Drawing.Imaging.ImageFormat
--------------------
Imaging.ImageFormat(guid: Guid) : unit
Full name: 200-image-processing-example.urls
Full name: 200-image-processing-example.tasks
Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.sprintf
static val DirectorySeparatorChar : char
static val AltDirectorySeparatorChar : char
static val VolumeSeparatorChar : char
static val InvalidPathChars : char[]
static val PathSeparator : char
static member ChangeExtension : path:string * extension:string -> string
static member Combine : [<ParamArray>] paths:string[] -> string + 3 overloads
static member GetDirectoryName : path:string -> string
static member GetExtension : path:string -> string
static member GetFileName : path:string -> string
...
Full name: System.IO.Path
type Uri =
new : uriString:string -> Uri + 5 overloads
member AbsolutePath : string
member AbsoluteUri : string
member Authority : string
member DnsSafeHost : string
member Equals : comparand:obj -> bool
member Fragment : string
member GetComponents : components:UriComponents * format:UriFormat -> string
member GetHashCode : unit -> int
member GetLeftPart : part:UriPartial -> string
...
Full name: System.Uri
--------------------
Uri(uriString: string) : unit
Uri(uriString: string, uriKind: UriKind) : unit
Uri(baseUri: Uri, relativeUri: string) : unit
Uri(baseUri: Uri, relativeUri: Uri) : unit
Full name: 200-image-processing-example.results