?
Solved

Auto Crop/Trim border of image in C#

Posted on 2014-11-11
10
Medium Priority
?
1,059 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 35

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 35

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 35

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 35

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 35

Accepted Solution

by:
ste5an earned 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

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…
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

770 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