Link to home
Start Free TrialLog in
Avatar of Calemont
Calemont

asked on

TIFF Image Redaction

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.
Avatar of jkr
jkr
Flag of Germany image

'CxImage' can do that IIRC, and it's free - see http://www.codeproject.com/Articles/1300/CxImage
Avatar of Calemont
Calemont

ASKER

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.
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
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.
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
If using an external tool is a possiblity you should even check ImageMagick, it's quite powerful: http://www.imagemagick.org/script/index.php
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
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
You're most welcome ;o)

And I am not the one to understand the purpose of that policy either...
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.
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.
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.
ASKER CERTIFIED SOLUTION
Avatar of Calemont
Calemont

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
I did it!