Use FSharp to explore dotnet image processing functions 2--balanced grayscale

Source: Internet
Author: User
Tags dotnet

Pick up the image processing at the university, as if nothing had been learned before, but why do I still keep the book? Hey.

See balanced grayscale processing, come up is integral, probability distribution formula, head slightly pain. Online read a little introduction, the next day pick up books, finally have a point of view. In short, the gray histogram of the probability distribution of the area of the constant stretch, so that the image has a better display effect.

In fact, there are very few operations.

1. Calculate the probability of the occurrence of gray values.

2. Sort the grayscale values and sliding scale progressively.

3. Map the values of the progressive sliding scale to the range of 0-255. Then there is a corresponding relationship between the original gray scale and the new gray scale. The formula is Y = (int) (c * p + 0.5) c is the target gray maximum value p is the progressive probability.

4. Replace each grayscale of the original with the target grayscale

The code is as follows

//the number of pixels
LetLength = (bitmap. Width * Bitmap. Height * Bitmap.getpixelformatsize (Bitmap. PixelFormat)/8) LetRarray = [| forIinch 0..2550uy|]buffer|> seq.groupby ID |> seq.map ( FunX-(FST x),Double(Seq.length (snd x))/Doublelength)//step 1|> Seq.sortby fst//step 2|> Seq.scan ( Fun(_, OP) (K,p) (K, p + op)) (0uy,0.0)//step 2|> Seq.map ( Fun(k, p), (intK, (byte)(255.0* p +0.5)) )//step 3|> Seq.iter ( Fun(k, p), Rarray. [K] <-p)//step 3 LetNewbuff = buffer |> Seq.map ( FunX-Rarray. [intX]) |> array.ofseq//step 4

Where GroupBy gets the key and the grouped list value. So after that, FST and snd were used.

Scan is really easy to calculate the increment value.

is not clear a lot.

Use FSharp to explore dotnet image processing functions 2--balanced grayscale

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.