?
Solved

Question Related Pixel Colors Of BMP/Jpeg, After Getting It Into The Handle

Posted on 2001-07-20
23
Medium Priority
?
283 Views
Last Modified: 2013-12-03
Hello Experts,

I have done a quite bit of programing with bmp's/jpegs using win32 sdk in VC++. Opening the files mixing two images, writing text over it, saving them back etc. types of manipulations I have done, after opening file in HDC handle.

Now I require one more feature for my Image-Related win32 application, for which as far as I am concerned I am not able to work out Any Algorithm(s) Or Any Concept(s), and I need your Help. Here it is ::

After the Bitmap/Jpeg is opened and shown to the user, the user can click on any point on it. I want to get the color of that pixel, no problem I will get it.

Now what I want more is, I have to Trace all those Pixels All-Around this very particular PIXEL, moving in any direction from it HAVING THE SAME COLOR.
The search should stop in any direction  when a pixel of different color is found.

Basically, what I have to do is to make the AREA black in the Bitmap, where a user pin-points and all the surrounding pxiels having the same pixel-color as the pin-pointed pixel color.

How to do that, please help me as soon as possible.

Best Regards
Robert

0
Comment
Question by:robert_9999
  • 12
  • 6
  • 4
  • +1
23 Comments
 
LVL 5

Expert Comment

by:robpitt
ID: 6301867
Sounds like you need a flood fill algorithm.
There are plenty of these on the net, heres the first one I found...
http://cs1.mcm.edu/~tmiller/courses/csc-4330/code/areaFill2.html

0
 
LVL 15

Expert Comment

by:NickRepin
ID: 6303728
Why not FloodFill() and ExFloodFill()?
0
 
LVL 5

Expert Comment

by:robpitt
ID: 6304096
Oh yeah, I'd forgotten about that one! :-)
0
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
LVL 5

Expert Comment

by:FengYuan
ID: 6305539
1) Find a good flood-fill algorithm. A simple flood-fill algorithm may have a maximum stack depth of n x m.
2) Change the algorithm to generate a set or region of all the pixels have the same color starting from a seed point.
3) Use FrameRgn to draw an outline around these pixels.
4) Use FillRgn to clear the area covered by these piexels, and move somewhere else using FillRgn again.
0
 

Author Comment

by:robert_9999
ID: 6308106
Thanks all for the instant support especially NickRepin. He was really very straight in finding the solution. But I have a  bit more query regarding my problem, please see to it, and for that fairly enough I have increased the points also. Here it is ::

You must have seen the Fuzziness (Tolerance) ranging from 0-255, in different graphical packages say most popular Photoshop, everything is OK in ExFloodFill(), it exacly does what I required, It goes in all outward directions until discontinued, relative to a pixel color selected.

But if I increase Fuzziness or Tolerance in PH. it does same but the range of colors selected increases. For example if I PICK a point in Image whose RGB is 245,200,118 and used EXFloodFill() it will go for exact 245,200,118 color in all directions but if I increase some value just like Tolerance in PH., the selection increases.

WHAT PHOTOSHOP SAYS IS may be that can help you ::

"Enter a low value to select colors very similar to the pixel you click or a higher value to select a broader range of colors.", in Tolerance(Fuzziness).

I think I have Asked you much and I guess this concept requires a prepared algo.

Best Regards
Robert
0
 
LVL 5

Expert Comment

by:robpitt
ID: 6308175
Yeah I think you'll definitely need a custom flood fill algortithm of some kind.

The crude one I point you too could easily be modified to allow a tolerance.

However as pointed out by FengYuan this kind of simple algorithm can potentially recurse upto WxH times which be too much for a large bitmap.

How big is your bitmap?
0
 
LVL 5

Expert Comment

by:robpitt
ID: 6308184
PS
Off the top of my head a way to adapt the basic algorthim reducing the potentail stack requirement would be to apply it to smaller rectangular sections at a time.
0
 

Author Comment

by:robert_9999
ID: 6308190
W-1800 and H-1200 that is 6 by 4 images at 300 DPI.
0
 
LVL 5

Expert Comment

by:robpitt
ID: 6308231
Thats certainly big enough to cause trouble in the event of an expensive fill scenario.

Lets see if the other guys have anything to say...
0
 

Author Comment

by:robert_9999
ID: 6308276
Lets See.
0
 

Author Comment

by:robert_9999
ID: 6308444
robpitt, I have worked out the size can reduced to 1200*1200 pixels, wothout much Effecting my program efficiency and working. Thanks

Best Regards
Robert

0
 

Author Comment

by:robert_9999
ID: 6308460
robpitt, I have worked out the size can reduced to 1200*1200 pixels, wothout much Effecting my program efficiency and working. Thanks

Best Regards
Robert

0
 

Author Comment

by:robert_9999
ID: 6311072
Waiting for ur comments experts.

Best Regards
Robert


0
 
LVL 5

Accepted Solution

by:
FengYuan earned 1200 total points
ID: 6311089
Reducing stack depth in floodfill:

bool CloseEnough(int x, int y, COLORREF crSeed)
{
    if ( (x<0) || (x>=width) )
        return false;

    if ( (y<0) || (y>=height) )
        return false;

    return Close(GetPixel(x, y), crSeed);
}

void FloodFill(int x, int y, COLORREF crSeed, COLORREF crFill)
{
repeat:

   int minx = x;
   
   while ( CloseEnough(minx-1, y, crSeed) ) minx --;

   int maxx = x;

   while ( CloseEnough(maxx+1, y, crSeed) ) maxx ++;

   FillScan(minx, maxx, y, crFill);

   if ( CloseEnough(x, y-1, crSeed) )
       FloodFill(x, y-1, crSeed, crFill);

   if ( CloseEnough(x, y+1, crSeed) )
   {
       y ++;
       goto repeat;
   }
}

www.fengyuan.com
       
0
 

Author Comment

by:robert_9999
ID: 6311316
I do not understand the above code FengYuan, please if possible explain it. Also please see the latest of my comments.

Anyway I went to ur site, I liked the book. What is the cost ??

Best Regards
Robert

0
 

Author Comment

by:robert_9999
ID: 6311399
What happened to u robpitt, I have considerable reduce the size of the image and also that can be broken ito smaller segments, Now I think your algo which U quoted above as U have can be applied for FLOODFILL With Tolerance.
0
 

Author Comment

by:robert_9999
ID: 6316041
No comment/suggestions, please reply FengYuan, robpitt NickRepin.

Best Regards
Robert
0
 
LVL 5

Expert Comment

by:robpitt
ID: 6316435
I'm afraid I have litle extra to add.

Is there a problem with using something based on Feng's post with its reduced stack requirement?

Rob
0
 
LVL 5

Expert Comment

by:FengYuan
ID: 6320697
A simple flood-fill algorithm would check four neighboring pixels, and recursively call with these coordinates.

This changed algorithm always tries to find a scanline, fill the scanline, and then only goes up and down with recursion. The down recursion is also optimized.

Try it, write a working code, and step through it.

www.fengyuan.com
0
 

Author Comment

by:robert_9999
ID: 6329674
Thanks FengYuan,

But what about Tolerance (Fuzziness) in it.

Best Regards
Robert

0
 
LVL 5

Expert Comment

by:FengYuan
ID: 6332037
That is for: "Fuzziness (Tolerance) ranging from 0-255"
0
 

Author Comment

by:robert_9999
ID: 6383117
Sorry Everyone Specially FengYuan, I was out of town without informing you all. I am very sorry for that. But here I am again to work practically on this. You were right, I was given this work by my boss and I was talking everything theoritically, but now the time has come and I will write the Working-Code and see.
Let's see how much time it takes.

Best Regards
Robert

0
 

Author Comment

by:robert_9999
ID: 6395906
Thanks All,

I am succeded in what I want.
Meanwhile I have two more questions, which I will ask one by one. I appreciate again your valuable help.

Best Regards
Robert

0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

850 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