Solved

Auto Crop/Trim border of image in C#

Posted on 2014-11-11
10
931 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
[X]
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
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

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…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

733 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