Solved

Auto Crop/Trim border of image in C#

Posted on 2014-11-11
10
861 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
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
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
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…

805 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