C # image programming (1) preparation; Hello, flight attendant; add special effects to the flight attendant photo

Source: Internet
Author: User
Tags image processing library
Document directory
  • (1) Prepare the experiment environment
  • (2) first script: Hello, Flight Attendant
  • (3) pixel operation demonstration-add luminous effects to photos
  • (4) episode

A long time ago, I wanted to write a series of C # image programming articles, but I never wrote them down. There are two main reasons: (1) My C # image processing database Geb. the Image library is greatly changed; (2) no good demo tool is found. Now, for the first question, the basic structure of the Geb. Image Library has been determined; for the second question, LinqPad is selected as the C # Image programming and demonstration tool, which is lightweight and simple. From now on.

(1) Prepare the experiment environment

Suppose you are familiar with C # programming and have a 32-bit. Net 4.0 environment on your computer. On this basis, we began to build an experimental environment for C # image programming.

Step 1: download and install LinqPad.

LinqPad is a compact and easy-to-use C # code snippet compilation tool. It has a free version and a paid version. The paid version provides more automatic functions than the free version. If you do not need to automatically complete the function, use the free version.

Step 2: Download The Geb. Image class library

Geb. Image is my C # basic Image processing library, address: https://github.com/xiaotie/GebImage

The directory structure is as follows. Here, we only use the dll Directory and scripts directory. As the name implies, dll is some basic dll, and scripts is the C # script written in this series of articles.

Step 3: Set LinqPad

Open LinqPad and press the [F4] shortcut key to enter the Query Properties setting interface. On the "Additional References" tab, add the dll in The dll Directory.

Then, add Geb. Image, Geb. Utils, and Geb. Utils. WinForm to "Additional Namespace Imports" and click "Set as Default for new queries" to save:

In this way, we add necessary dll references and common namespaces.

Next, click the "Set Folder..." link in the lower left corner of LinqPad to Set the scripts directory to the working directory:

Each file displayed in the working directory is a C # script file. Double-click to load the file.

(2) first script: Hello, Flight Attendant

In the working directory, double-click "1-1-show image" to see:

This script loads the displayed image. Before running the script, change the baseDir directory to the actual path of the scripts/img directory. Click the green triangle button and a pair of familiar faces will appear:

(3) pixel operation demonstration-add luminous effects to photos

Next, we use the photo of the flight attendant as the test photo to implement the luminous special effect algorithm:

Luminous effects are easy to implement: Change the Red value of each pixel in the image to 1/2 of the current value. The program file is scripts \ 001 \ 1-2-luminous special effect. linq. Here we use four methods to implement this function to demonstrate pixel operations:

String baseDir = "E: \ MyWorkspace \ DotNetWorkspace \ 01_Public_Geb.Image \ scripts \ img \"; unsafe void Main () {ImageRgb24 img = new ImageRgb24 (baseDir + "cjk.jpg"); img. showDialog ("img"); // views the image as a continuous memory and uses the offset to access ImageRgb24 img2 = img. clone (); for (int I = 0; I  Red = (Byte) (p-> Red/2); p ++ ;}} img4.ShowDialog ("img4 "); // access ImageRgb24 img5 = img through lambda expressions. clone (); img5.ForEach (Rgb24 * p) => {p-> Red = (Byte) (p-> Red/2 );}); img5.ShowDialog ("img5"); // Dispose can release the memory occupied by images. Without Dispose, when the GC destroys an object, the non-managed memory is also released. // Img. Dispose (); // img2.Dispose (); // img3.Dispose (); // img4.Dispose (); // img5.Dispose ();}

Is it easy? The following is the entertainment time.

(4) episode

Why use a flight attendant as a demo image? Let's start with Dao Mei.

In the League of legends game, there is a hero with the nickname "blade will", ireia, also known as Dao Mei. Dao Mei is a violent sister-in-law paper-"The sword is flying like a blood painting ".

Because of the violent nature, Dao Mei was often weakened, sometimes 12 times in a row and 22 times in a row. That's why "so-and-so is too strong. Let's weaken the knife girl !" It became a buzzword in the Internet: galun is too strong. Let's weaken the knife sister. The card is too strong. Let's weaken the knife sister; today's weather is good. Let's take a look at it...

In the image processing field, there is also a ubiquitous sister paper, Lena:

Lena is a playboy Cover Girl in 1972. Since 1973, when someone used this photo in his paper, this image has become the most commonly used test image, she can be seen in almost every image processing book.

In every corner of the Earth, such voices have been changing for more than 40 years:

After the program is written, use Lena to test it;

The algorithm is optimized. Let's test it with Lena;

......

In the east, the flight attendant has more affinity than Lena, and I will not use Lena as the test image, instead of the flight attendant.

After the program is completed, let's test it with the flight attendant;

The algorithm is optimized. Let's test it with the flight attendant;

......

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.