C ++ Image Processing-image flip (image)

Source: Internet
Author: User
Tags image flip

Reading Tips:

C ++ image processing SeriesCodeIt is clear and readable, and all uses C ++ code.

Delphi Image ProcessingThe series focuses on efficiency. The general code is Pascal, and the core code is BaSm.

Make sure that the two items are consistent and can be compared with each other.

The code in this article must include "C ++ Image Processing-data types and common functions"Article.

 

The image flip process generates an image that is opposite to the original image in the horizontal or vertical direction.

The principle of image flip is very simple, that is, based on the pixel (horizontal direction) in the middle column of the image, or the middle row pixel (vertical direction) as the base column (ROW), the first column (ROW) of the image) the pixels of the image are exchanged with the pixels in the last (ROW) column of the image, and the pixels in the second (ROW) column of the image and the second (ROW) column of the image) pixel switching ......, until the base column (ROW), if the number of columns (rows) in the image is an even number, the columns (rows) at the beginning and end of the image are exchanged, including the base column (ROW, if the number of columns (rows) in the image is an even number, the base column (ROW) remains unchanged, and the columns (rows) corresponding to other headers and tails are exchanged in pairs.

The following is the implementation code and example of image flip.Program(Use bcb2010 and GDI + ):

// Inclutypedef Enum {reversalmodehorizontal, // horizontal flip reversalmodevertical // vertical flip} reversalmode; // image flip (image) void imagereversal (bitmapdata * data, reversalmode mode Mode) {uint width = data-> width; uint Height = data-> height; int srcoffset = data-> stride> 2; int dstoffset, Delta; pargbquad PD, PS; argb color; If (mode = reversalmodehorizontal) {Pd = (pargbquad) Data-> scan0; PS = Pd + width-1; dstoffset = srcoffset; Delta =-1; width >>=1;} else {PS = (pargbquad) Data-> scan0; Pd = Ps + (height-1) * srcoffset; dstoffset =-srcoffset; Delta = 1; height >>=1 ;}for (uint y = 0; y 

The image after the example is run is as follows, with the source image on the left and the horizontal image on the right:

 

Due to limited levels, errors are inevitable. Correction and guidance are welcome. Email Address:Maozefa@hotmail.com

You can access 《C ++ Image Processing-document indexing".

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.