views:

106

answers:

5

How do I generate a list of lines to draw if I have pixel data for an image, so I don't have to draw every pixel? Any language will do, although I listed what I have a working knowledge for. C is ok as well. There was a limit to how many tags I could choose. Also, you can just point me toward an algorithm.

A: 

How can you achieve with lines what you have to do with pixels? You need to draw each pixel individually I'd say.

nakiya
+1  A: 

In general, bitmaps are stored in sequential memory, ideal for 'blitting' to the display; your GUI framework of choice will have a function for drawing bitmaps, and this function will be very carefully optimised.

On the other hand, decomposing an image into lines - vectorizing the image - is the domain of specialist programs and ongoing research. In all cases, its going to be slower to computer and slower to draw than just blitting the bitmap.

Will
+1  A: 

You are looking for a "raster to vector" algorithm. The term comes from early graphics display systems, that used a CRT (cathode ray tube) for the display itself. There were 2 approaches to displaying graphics: "raster" was the scan of a series of lines left to right, top to bottom, each line made up of on/off pixels. The controller of the CRT's electron gun simply scanned the same pattern over and over, just varying the intensity of the electron beam. On a "vector" display, the electron gun could draw a straight line between any two points - no aliasing, no pixelation, just a pure straight line. Vector displays were capable of higher resolution, but were limited by the number of lines they could draw - if a drawing had too many lines, then the display would begin to flicker as the time it would take to redraw the picture (to refresh the phosphors of the CRT) would take longer than the persistence of the CRT's phosphor surface. Raster displays were simpler to control, had much less flicker, but lower resolution.

Paul McGuire
+1  A: 

If you want to extract lines from an image, try the Hough transform. , Check out also Reversible Straight Line Edge Reconstruction, which appeared in Graphics Gems V. The code is online at http://tog.acm.org/resources/GraphicsGems/gemsv/ch6-5/

lhf
Not only do I not think that this is quite what the OP is looking for, but a raw Hough transform doesn't identify endpoints: that is it get lines, not line segments...
dmckee
A: 

Opencv has functions named like "cvHoughLines2" to detect lines.

Zhongzhi