Interesting programming: automatic "seek fault" using LINQ"

Source: Internet
Author: User
Document directory
  • Can I find the five differences between the left and right parts?
  • It doesn't matter if you can't find it. Use a program to process the image.
  • The result is as follows:
Can I find the five differences between the left and right parts? It doesn't matter if you can't find it. Use a program to process the image. Using system; <br/> using system. collections. generic; <br/> using system. drawing; <br/> using system. drawing. imaging; <br/> using system. LINQ; <br/> using system. windows. forms; <br/> using system. runtime. interopservices; </P> <p> namespace spotdiff <br/> {<br/> Public partial class form1: Form <br/>{< br/> Public form1 () <br/>{< br/> initializecomponent (); <br/>}</P> <p> private void processbutton_click (Object sender, eventargs E) <br/>{< br/> var BMP = picturebox1.image as bitmap; <br/> var rect = new rectangle (0, 0, BMP. width, BMP. height); <br/> var bmp data = BMP. lockbits (rect, imagelockmode. readwrite, pixelformat. format24bpprgb); <br/> var PTR = BMP data. scan0; <br/> var bytes = BMP data. stride * BMP. height; <br/> var rgbvalues = new byte [bytes]; <br/> marshal. copy (PTR, rgbvalues, 0, bytes); </P> <p> var W = BMP. width/2; <br/> var H = BMP. height; <br/> var dx = 0; <br/> List <point> PTS = NULL; <br/> var lastsim = 0.0; <br/> (; DX <W; ++ dx) <br/>{< br/> PTS = getsimilarpoints (BMP data, rgbvalues, W, H, dx ); <br/> var SIM = PTS. count ()/(double) (W-dx) * H); <br/> system. diagnostics. debug. writeline (SIM); <br/> If (SIM <lastsim) {<br/> PTS = getsimilarpoints (BMP data, rgbvalues, W, H, -- dx ); <br/> break; <br/>}< br/> lastsim = SIM; <br/>}</P> <p> If (DX <W) <br/> foreach (var pt in PTS) <br/>{< br/> var offset1 = pt. y * BMP data. stride + Pt. x * 3; <br/> var offset2 = pt. y * BMP data. stride + (pt. X + W + dx) * 3; <br/> rgbvalues [offset1] = 255; rgbvalues [offset2] = 255; <br/> rgbvalues [offset1 + 1] = 0; rgbvalues [offset2 + 1] = 0; <br/> rgbvalues [offset1 + 2] = 0; rgbvalues [offset2 + 2] = 0; <br/>}</P> <p> marshal. copy (rgbvalues, 0, PTR, bytes); <br/> BMP. unlockbits (BMP data); <br/> picturebox1.refresh (); <br/>}</P> <p> Private Static list <point> getsimilarpoints (bitmapdata BMP data, byte [] rgbvalues, int W, int H, int dx) <br/>{< br/> return (<br/> from X in enumerable. range (0, W-dx) <br/> from Y in enumerable. range (0, h) <br/> let offset1 = y * BMP data. stride + x * 3 <br/> let offset2 = y * BMP data. stride + (x + W + dx) * 3 <br/> where rgbvalues [offset1] = rgbvalues [offset2] & <br/> rgbvalues [offset1 + 1] = rgbvalues [offset2 + 1] & <br/> rgbvalues [offset1 + 2] = rgbvalues [offset2 + 2] <br/> select new point (X, y )). tolist (); <br/>}< br/>The result is as follows:

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.