User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 456,584 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,630 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 426 | Replies: 3
Reply
Join Date: Sep 2006
Location: Michigan State University, United States
Posts: 232
Reputation: FireSBurnsmuP is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 1
FireSBurnsmuP's Avatar
FireSBurnsmuP FireSBurnsmuP is offline Offline
Posting Whiz in Training

Image searching...

  #1  
Nov 5th, 2007
Alright, I'm developing a program that is going to take in .pbm image files, manipulate them, and output them in .ppm (P3) format.

That's all fine and good; I've got that down.
However, I'm looking for suggestions on good and efficient ways to figure out if 2 points ( row , col ) are connected in an object within an object. By object I mean a region of all one colour, that has no diagonal connectivity. If I figure this out fast enough, I will implement a diagonal-connectivity checker as well.

Any suggestions? I was thinking about using an STL stack to store my moves, in case I end up at a dead end, so I can go back a few moves and take another possible road. something like this (but I don't think this is efficient enough for me.), conceptually.
push all possible moves in order W , S , E , N - impossible moves are moves that go outside the region.
These will be something like a struct I'll call move, like this:
struct point
{
     int row;
     int col;
};
struct move
{
     point here;
     point next;
};
pop off the last possibility and go that way.
repeat.
if I run out of possibilities for moves (a dead end) pop and set my position to the next in the first alternative possibility and go forth.


However, it seems to me that if I were to go that way, with the specific order of directions to take, it would be horribly inefficient.

Any ideas? I'll be much obliged. I just wanna bounce ideas.
Damn the man! Save the Empire!
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation: Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold 
Rep Power: 13
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: Image searching...

  #2  
Nov 5th, 2007
I'm not sure exactly what you are trying to do.

What exactly do you mean by "moves"? By "object" do you mean a raster color run (a horizontal line of the same color)?

What is the purpose of doing this? The ppm format is as horribly inefficient as pbm, the only real difference is that it stores RGB colors instead of on/off. It has no compression or organization other than a simple list of pixels in raster order.

If you can explain it better with pictures, I don't mind.
Reply With Quote  
Join Date: Sep 2006
Location: Michigan State University, United States
Posts: 232
Reputation: FireSBurnsmuP is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 1
FireSBurnsmuP's Avatar
FireSBurnsmuP FireSBurnsmuP is offline Offline
Posting Whiz in Training

Re: Image searching...

  #3  
Nov 7th, 2007
The reason I'm using these formats is that they're a good place to start off. I'll eventually make this program able to handle many types of pictures, but I've got to start somewhere ^_^

Alright, time for some ascii-art goodness.
I'll start with a small binary picture. [ ][X] for off/on

10x5
0 1 2 3 4 5 6 7 8 9
0[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
1[ ][X][ ][ ][ ][ ][X][X][X][ ]
2[ ][X][X][ ][ ][ ][X][ ][X][ ]
3[ ][X][X][X][ ][ ][X][X][X][ ]
4[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]

Alright. there's the picture. Now I'm looking for the best (efficiency) algorithm in c++ to test if the pixels (1,1) and (7,1) are connected.

As of now, the program attempts to go N, if that doesn't work it goes E, if that doesn't work it goes S, and if that doesn't work it goes west. It does this until it can no longer go anywhere.
I would like it to go in an order that changes depending on what direction the destination is from the starting point, but that ends up being inefficient in other ways. any ideas are good, thanks.

Or, should I start by checking how many borders I cross between the start and end, going directly at each other? in this case, I would pass 2 boundaries, meaning either the region wraps like a U to the destination or there are two regions involved.
What do you think?

[edit] apparently it doesn't like my ascii-art. You get the idea, though. it's a triangle seperated from a square with a hole in it.
Last edited by FireSBurnsmuP : Nov 7th, 2007 at 12:52 am.
Damn the man! Save the Empire!
Reply With Quote  
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation: Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold Duoas is a splendid one to behold 
Rep Power: 13
Solved Threads: 193
Featured Poster
Duoas's Avatar
Duoas Duoas is offline Offline
Posting Virtuoso

Re: Image searching...

  #4  
Nov 7th, 2007
Ah, I get it. Google "flood fill algorithms".

To get ASCII art to look right just put it in [code] tags:
10x5
  0  1  2  3  4  5  6  7  8  9
0[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]
1[ ][X][ ][ ][ ][ ][X][X][X][ ]
2[ ][X][X][ ][ ][ ][X][ ][X][ ]
3[ ][X][X][X][ ][ ][X][X][X][ ]
4[ ][ ][ ][ ][ ][ ][ ][ ][ ][ ]

Good luck.
Last edited by Duoas : Nov 7th, 2007 at 3:57 am.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 6:32 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC