Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Auto Crop/Trim border of image in C#

Posted on 2014-11-11
10
900 Views
Last Modified: 2014-11-12
Hello everyone,
I'm trying to remove the surrounding color from the scanned image. I've a scanned page of book but it comes with some surrounding color (e.g grey color). I am trying to cut just the book page leaving the surrounding color. So, far I've tried GDI+ and AForge but nothing seems to work accurately.

Is it even possible (or I'm trying in vain) to automate the trim of surrounding color from the scanned image in C#?

Kindly suggest and any working link would be great help.

Regards
0
Comment
Question by:tech1guy
  • 5
  • 5
10 Comments
 
LVL 33

Expert Comment

by:ste5an
ID: 40438277
What are your objectives here? Why not automating Gimp/Paint.net/Photoshop..?
0
 

Author Comment

by:tech1guy
ID: 40438430
I wrote a script to take screen shots of running application after every 2 seconds. Now, those screen shots needs to be cropped of the surrounding space within the C# code. I've tried the following link to crop: http://pastebin.com/FADb57fq

but it crops certain images only but not all. I'm not sure what's wrong. Any help would be a boon for me.
0
 
LVL 33

Expert Comment

by:ste5an
ID: 40438443
How do create the screen shots? Script??
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:tech1guy
ID: 40438475
Yes, CopyFromScreen (within a C# method/script) method is used to capture the screen. Basically, screen shots are captured while a certain desktop application is running and it's done for the Audit purposes.
0
 
LVL 33

Expert Comment

by:ste5an
ID: 40438546
I would use some more low-level style programming to copy just the window I want. Here is a C++ sample showing what steps it needs. Here you'll find a C# wrapper for it: Capture a Screen Shot. And here the same in VBA.
0
 

Author Comment

by:tech1guy
ID: 40438571
Thanks for the link but I'm stuck at the removing the grey color surrounding each screen shot. I've no problem in taking the screen shot. Could you please suggest something to remove the surrounding color from the image?
0
 
LVL 33

Expert Comment

by:ste5an
ID: 40438688
I would really reconsider the approach...
0
 

Author Comment

by:tech1guy
ID: 40438691
That's a good idea. Thanks. But in general removing the surrounding colors from the scanned images would be a nice tool to have. Any ideas on that one?
0
 
LVL 33

Accepted Solution

by:
ste5an earned 500 total points
ID: 40438738
Are we talking about a general approach or have we some boundary constraints?

The general approach would be a creating a histogram to get the color distribution and then get pixel by pixel to the inner to get the edge of the desired window. The histogram may be your mentioned gray colour.

Another approach could be getting the window coordinates and use them to define your cut edges.
1
 

Author Closing Comment

by:tech1guy
ID: 40438752
Thanks very much for the ideas!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question