Solved

Auto Crop/Trim border of image in C#

Posted on 2014-11-11
10
798 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 32

Expert Comment

by:Stefan Hoffmann
Comment Utility
What are your objectives here? Why not automating Gimp/Paint.net/Photoshop..?
0
 

Author Comment

by:tech1guy
Comment Utility
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 32

Expert Comment

by:Stefan Hoffmann
Comment Utility
How do create the screen shots? Script??
0
 

Author Comment

by:tech1guy
Comment Utility
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 32

Expert Comment

by:Stefan Hoffmann
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:tech1guy
Comment Utility
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 32

Expert Comment

by:Stefan Hoffmann
Comment Utility
I would really reconsider the approach...
0
 

Author Comment

by:tech1guy
Comment Utility
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 32

Accepted Solution

by:
Stefan Hoffmann earned 500 total points
Comment Utility
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
Comment Utility
Thanks very much for the ideas!
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Article by: Ivo
Anonymous Types in C# by Ivo Stoykov Anonymous Types are useful when  we do not need to follow usual work-flow -- creating object of some type, assign some read-only values and then doing something with them. Instead we can encapsulate this read…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now