C # Digital Image processing Algorithm learning notes (III.)--Image geometric transformation

Source: Internet
Author: User

C # Digital Image processing Algorithm learning notes (III.)--Image geometric transformation

The geometric image processing includes the image translation transformation, the mirror transformation, the rotation transformation, the telescopic transformation, in this case only with the horizontal mirror as an example, through the code to understand its basic operation way:

Before flipping:

After flipping:

//Backstage code:
Public Partial classForm1:form {Private string_curfilename; PrivateBitmap _srcbitmap; PrivateBitmap _dstbitmap; PublicForm1 () {InitializeComponent (); } Private voidOpen_click (Objectsender, EventArgs e) {OpenFileDialog Opndlg=NewOpenFileDialog (); Opndlg.filter=@"all image files |*.bmp;*.pcx;*.png;*.jpg;*.gif;"+@"*.tif;*.ico;*.dxf;*.cgm;*.cdr;*.wmf;*;eps;*.emf|"+@"bitmap (*.bmp;*.jpg;*.png; ...) | *.bmp;*.pcx;*.png;*.jpg;*.gif;*.tif;*.ico|"+@"vector diagram (*.wmf;*.eps;*.emf; ...) | *.DXF;*.CGM;*.WMF;*.EPS;*.EMF"; Opndlg.title=@"Open an image file"; Opndlg.showhelp=true; if(Opndlg.showdialog () = =DialogResult.OK) {_curfilename=Opndlg.filename; Try{_srcbitmap=(Bitmap) image.fromfile (_curfilename); } Catch(Exception ee) {MessageBox.Show (EE. Message); }} Invalidate (); } Private voidClose_click (Objectsender, EventArgs e) {application.exit (); } Private voidForm1_paint (Objectsender, PaintEventArgs e) {Graphics g=E.graphics; if(_srcbitmap! =NULL) {g.drawimage (_srcbitmap, the, -, _srcbitmap.width, _srcbitmap.height); } }
//Flip processing function, here is the two pictures to flip the operation, or can be flipped directly with a picture, but to pay special attention to each pixel accounted for 3 byte bits, and flip the whole pixel is flipped together Private voidMirror_click (Objectsender, EventArgs e) { if(_srcbitmap! =NULL) {_dstbitmap=(Bitmap) _srcbitmap.clone (); BitmapData Bmpdata= _srcbitmap.lockbits (NewRectangle (0,0, _srcbitmap.width, _srcbitmap.height), Imagelockmode.readwrite, _srcbitmap.pixe Lformat); BitmapData Dstdata= _dstbitmap.lockbits (NewRectangle (0,0, _dstbitmap.width, _dstbitmap.height), Imagelockmode.readwrite, _dstbitmap.pixelformat); unsafe { byte* p = (byte*) Bmpdata.scan0; for(inty =0; Y < Bmpdata.height; y++) { for(intx =0; x < bmpdata.width; X + +) { byte* DSTP = (byte*) Dstdata.scan0 + y*dstdata.stride + x*3; dstp[0] = p[bmpdata.width*3-(x +1)*3]; dstp[1] = p[bmpdata.width*3-(x +1)*3+1]; dstp[2] = p[bmpdata.width*3-(x +1)*3+2]; } P+ = Bmpdata.stride;//Stride for scan width Stride > bmpdata.width * 3, Width indicates the number of pixels per row, 3 byte bits per pixel} _srcbitmap.unlockbits (Bmpdata); _dstbitmap.unlockbits (Dstdata); } _srcbitmap=(Bitmap) _dstbitmap.clone (); Invalidate (); } } }

Other geometries are similar to this operation, which operates directly on the original data through pointers, but pay particular attention to the cross-check of pointers.

C # Digital Image processing Algorithm learning notes (III.)--Image geometric transformation

Related Article

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.