Solved

TIFF Image Redaction

Posted on 2014-02-06
16
649 Views
Last Modified: 2014-03-05
I have a C++ 2010 project that requires I remove a portion of an image.  I have access to Accusoft Imagegear, but not their IGArt Object.  This means I'm not able to draw on the TIFF image being redacted; so MarkCreate, MarkPaint, and ImageBurnIn are not an option to overlay anything.

I've gotten this to work by using Imagegear's SetClipboardCut function.  It works, but it's messy and occupies the user's clipboard while running.  Unfortunately, I'm not seeing anything else available.  The Crop function would have worked if I could set it to crop out the defined area rather than crop to the defined area.

If anyone knows a better Imagegear tool to use than SetClipbordCut to remove a defined area within a TIFF image, I would appreciate being directed towards it.

Thank you.
0
Comment
Question by:Calemont
  • 6
  • 4
  • 2
  • +2
16 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 39840085
'CxImage' can do that IIRC, and it's free - see http://www.codeproject.com/Articles/1300/CxImage
0
 

Author Comment

by:Calemont
ID: 39840096
I can push for the addition of CxImage in our policy, but that's not going to see approval by the time this current issue comes due.  Imagegear is the tool I have available, unfortunately.
0
 
LVL 30

Expert Comment

by:Zoppo
ID: 39840112
Hi Calemont,

what exactly do you want to acchieve?

If you just want to "remove a portion" (which I understand as 'delete or fill an area defined by a polygons with a color or transparency') this IMO can be easily done using GdiPlus in your program (I guess it's for Windows because you wrote "C++ 2010" project) where you can simply load a TIFF into a Gdiplus::Bitmap, create a Gdiplus::Graphics which works somehow similar to a device context, so you can perform common drawing operations which directly affect the loaded TIFF, then you can save it again.

If you're interested you can find a simple code sample i.e. here: http://colonelpanic.net/2010/11/resizing-an-image-with-gdi-with-cpp/

Hope this helps,

ZOPPO
0
 

Author Comment

by:Calemont
ID: 39840174
It's being developed on Windows 7, but is required to be compatible with older versions as well.  We may even have an XP machine or two that could end up using this.

I actually re-wrote large portions of this code using GDIPlus back in 2009 in an attempt at better reliability and functionality.  It was shot down then, and will likely happen again.

Really.  Stuck using gear.cpp without access to their art objects, though I do appreciate the recommendations and will be putting together approaches for better tools for moving forward.

As for what I'm trying to achieve?  Take rectangle coordinates from a file relating to an image.  Whatever data is beneath that rectangle; remove it from the image.  It's a fairly simple operation.  Or at least it should be if not for the environment.

SetClipboardCut works.  It requires me to monitor the clipboard itself and empty it as I move through a batch -- and make sure that memory is not leaking because of the function.  It also isolates a user from their clipboard while the batch is being processed.

That's not exactly optimal, but it may be what they're stuck with because of their decisions.  I was hoping for a better IG tool that didn't require pushing new C++ classes past our auditors.
0
 
LVL 51

Expert Comment

by:Joe Winograd, EE MVE
ID: 39840266
IrfanView is excellent (free!) imaging software that I've been using for many years:
http://www.irfanview.com/

Click the Download link on the left to download IrfanView and click the PlugIns link on the left to download the PlugIns, which are needed to give you PDF capability (it's optional...only if you want PDF support...and the other features that come with the PlugIns). Install IrfanView first, then install the PlugIns (again, it's optional, but I think it's a good idea). Although I recommend adding the PlugIns to get PDF support, that's for general, future usage. For this situation, you don't need them, as IrfanView will handle your TIFF files without the PlugIns.

IrfanView has a GUI and command line interface. Of course, to call from your C++ program, you'll use the CLI. After you install it, you'll find all of the command line options in a file in the install folder (typically, C:\Program Files (x86)\IrfanView\) called <i_options.txt> (I also attached it to this post for the latest IrfanView version, 4.37).

The option you'll use is:

/crop=(x,y,w,h,C)

where the parameters are x-start, y-start, width, height, C-start corner (0-4)

and the corner values are:

0 = Left top, 1 = Right top, 2 = Left bottom, 3 = Right bottom, 4 = Center

For example:

i_view32.exe c:\folder\test.tif /crop=(10,10,300,300,0)

I've used <i_view32.exe> calls in many programs – works very well! Here's an EE article with one example. Regards, Joe
IrfanView-4.37-i-options.txt
0
 
LVL 30

Expert Comment

by:Zoppo
ID: 39840320
If using an external tool is a possiblity you should even check ImageMagick, it's quite powerful: http://www.imagemagick.org/script/index.php
0
 
LVL 51

Expert Comment

by:Joe Winograd, EE MVE
ID: 39840352
If you're going to consider ImageMagick, you should also look at GraphicsMagick:
http://www.graphicsmagick.org/

GraphicsMagick is a fork of ImageMagick that began more than 10 years ago and has evolved independently of ImageMagick since then. Each product has its advocates and it's likely that one is not always better than the other, but I was recently involved in a website dev project that started with ImageMagick and then switched to GraphicsMagick with better results. All of that said, I still think that IrfanView can do exactly what you're looking for. Regards, Joe
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 51

Expert Comment

by:Joe Winograd, EE MVE
ID: 39840909
jkr,
You are absolutely correct. He wrote, "If anyone knows a better Imagegear tool...", but my mind saw, "If anyone knows a better tool..." I then started writing a reply and failed to read other posts in the thread where he made it quite clear that he is restricted to using Imagegear. Thanks for the wake-up on that. Regards, Joe
0
 
LVL 86

Expert Comment

by:jkr
ID: 39840921
You're most welcome ;o)

And I am not the one to understand the purpose of that policy either...
0
 
LVL 16

Expert Comment

by:HooKooDooKu
ID: 39841913
First of all, I though GDIPlus was backwards compatible to XP.  I too work with TIFF images, and wrote an application that uses CXImage to decompress the TIFF, but then uses GDIPlus to handle drawing the image on the window.  I only recall in my testing that only certain versions of Win2K couldn't run it.

In the mean time, is it possible to use SetClipboardCut twice in a row... basically "cut" the section of the image you want to hide... then "cut" the top left pixel of the image.  That way, when you are done with a double cut, the only thing left in the clip-board is a single pixel rather then monitoring the clipboard.
0
 

Author Comment

by:Calemont
ID: 39889119
Actually, you can use the following...

OpenClipboard();
EmptyClipboard();
CloseClipboard();

... to clear out anything left over.  Your method might be more efficient.  But that part wasn't worrying me.  Hijacking the system ClipBoard to begin with was.  And it turns out that was a valid concern...

After going forward with the SetClipboardCut function, I found that it works VERY efficiently.  So I stopped worrying.

But then the code went to a group of users addicted to PrintNow for document production.  That background process intercepts my cuts and sends them directly to the printer.  I showed the users how to stop PrintNow long enough to run the redaction process, but we're back into the cut function being non-optimal.  Plus it's a security issue if a user decides NOT to stop PrintNow and ends up with a hardcopy stack of everything I just removed from the images.

Joe Winograd -- HUGE fan of IRFanView over here.  I've never managed to convince management to implement it system-wide, but I do have a personal version on my workstation that's great for batch conversion and other file functions.

It looks like that /crop function is meant to be used against files written to disk.  Does it have the option of working against a memory object?  Our current process extracts images from a BLOB into memory, modifies them there, and then writes them directly to a .ZIP file for transmission.

With the Clipboard function now causing procedural changes for at least one of our sites, that gives me greater leverage in pushing through draw options.

Oh, and JKR - the purpose of that policy is just that we have very tight auditors who's minds I've always had difficulty changing when it comes to implementing new tools.  It's a slow, painful process that was not going to meet the deadline of this project.  Now that I have something in production, there's more time to work on them in allowing better solutions.
0
 

Author Comment

by:Calemont
ID: 39889988
By the way -- if anyone is familiar with the various FX functions (Blur, Diffuse, Pixelate...), I might be able to use those.  Blur or pixelate my defined rectangle enough and nothing should be readable.

Unfortunately, they're not working as I'd expect them to work.  For both Cropping and SetClipboardCut, I just define a ProcessingRect and then Set the function:

m_igGear.ProcessingRectSet (lCropRectX, lCropRectY, lCropRectWidth, lCropRectHeight);
m_igGear.SetClipboardCut (true);
//or...
m_igGear.SetCropImage (true);

Open in new window


Both of those work just fine.  The FX functions seem to work a little differently:

m_igGear.ProcessingRectSet (lCropRectX, lCropRectY, lCropRectWidth, lCropRectHeight);
m_igGear.SetFXDiffuse(16);

Open in new window


Has no effect on the image.  Does it require a different rectangular definition than the other Image Processing calls?  Is there, perhaps, a call to apply the diffusion after it's been set?  I'm using the same calls to save the image after modification, but the FX calls just aren't doing anything.

Honestly, m_igGear.ContrastAdjust managed to excite me.  I should have been able to drop the pixels to 0 intensity, but again -- the call had no effect on the image.




EDIT -- hold on.  Are the FX calls and ContrastAdjust going to have any meaning on a bitonal image?  That might be why I'm not seeing any change.
0
 

Accepted Solution

by:
Calemont earned 0 total points
ID: 39895812
Good News, Everybody!  I finally managed to secure some documentation on the calls that I'm making.  It turns out that, yes, most of the Blur/Diffuse/Contrast options are only available on 4-bit or higher images.  As these are bitonal, their application is invalid.

That did lead me to discover the SetEncrypt method, which fortunately makes use of the processing rectangle (allowing me to maintain my established targeting).  It's not as clean as the empty white area produced by a cut, but it also does not rely on use of the system clipboard.

Thanks for the suggestions, though, and I'm going to be pushing for better image processing tools such as CxImage and a revist of GDIPlus.
0
 
LVL 51

Expert Comment

by:Joe Winograd, EE MVE
ID: 39897603
Hi Calemont,
Thanks for posting the good news. You may want to consider giving points to the folks who tried to help you. Of course, you don't have to...it's entirely up to you. In my case, even when I accept my own post as the answer, I always give points to the experts who tried to help...but that's just me...do whatever you think is the right thing to do. Either way, I was happy to try to help you. Regards, Joe
0
 

Author Closing Comment

by:Calemont
ID: 39905891
I did it!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

705 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

19 Experts available now in Live!

Get 1:1 Help Now