I have a image with horizontal and vertical lines. In fact, this image is the BBC website converted to horizontal and vertical lines. My problem is that I want to be able to
iterate from left to right until you hit a color pixel then use modified flood fill algorithm. more info on the algo flood fill @ wiki
There are several different approaches to your problem. I'd use a morphological image processing tool like this one. You will have the flexibility to define "rectangle" even something that not "exactly closed" (where the fill algorithm will fail).
Another possibility could be to use a machine learning approach, which basically is more data-driven than definition-driven like the previous one. You'll have to give your algorithm several "examples" of what a rectangle is, and it will eventually learn (with a bias and an error rate).
The flood fill would work, or you could use a modification of an edge tracking algorithm.
what you do is: create a 2d array (or any other d2 data struct)- each row represents a horizontal pixel line on screen, and each column a vertical line
iterate through all the pixels, left to right, and whenever you find a coloured one add its coordinates to the array
iterate through the array and findying lines and storing the begin and end pixel for each one (different data structure)
knowing that the begin of each line is its left/top pixel, you can easily check to see if any 4 lines comprise a rectangle
I believe you are looking for the generalized Hough transform.
In computer vision there is a algorithm called Generalized Hough Transform which maybe can solve your problem. There should be open source code having implemented this algorithm. Just search for it.
Opencv (image processing and computer vision library written in c) has implementation for hough transform (the simple hough transform find lines in an image, while the generalized one finds more complex objects) so that could be a good start. For the rectangles which do have closed corners there are also corner detectors such as cornerHarris which can help.
I ran the houghlines demo provided with opencv and here's the result on the image you gave (detected lines marked in red):
(source: splintec.com)