Hi.

that sums it ups.

i'm looking for C or asm code to do (fast :D !) simple operations on RGB pictures in RAM.
Well, in fact, the data is 8bit grayshade.

the things i need to do are pretty simple, find the coords of white blobs on a dark  picture; and i would like to know if some of you guys could tell me if this kind of things exist for free (or where i could search) because i'm not certain i would get it right easily myself.

(blobs are of somewhat fixed size and shape (circle) but there ccan be two quite near, etc...)

Thank you very much!

Posted on 2006-11-18 02:20:42 by HeLLoWorld
Hi
Look for the Pixelmap object and the demo. It is intended for 32 bit pixels but can be converted with little effort to 8 bit.

Regards,

Biterider
Posted on 2006-11-18 02:43:22 by Biterider
Going to do medical image processing? :)
Posted on 2006-11-18 02:46:51 by f0dder
What's your definition of white blobs on dark picture?

I was thinking that maybe a simple floodfill would be sufficient for your needs.
Posted on 2006-11-18 19:42:24 by roticv
Hi,

What you need to do is a litho of the image to set every pixel above a certain value to white and below that value to black. It is then a simple matter of getting the coordinates of the white pixels, you can use a type of fllod fill (without actually filling anything) to find the center point of the blob. The type of flood fill to use is  aline scanning, you need only to find the furthest left/right/top/bottom points of the "blob" and you can then give a good estimate of the center of the blob.

I use an image lithography technique in the LithoImage function of my graphics library, the function calculates teh relative luminosity of a pixel and determines whether it is above or below the threshold value. it is exclusively for 32 bit DIBs but is easily convertible to other formats...

LithoImage
Generates a lithograph (B&W image) of a 32 bit DIB section
Parameters
hBitmap = Handle to a 32 bit DIB section
Threshhold = Value from 0-255 that determines the LUMA value where the split occurs
Returns the original bitmap handle, the original image is modified

Tested GoAsm & MASM


LithoImage FRAME hBitmap,Threshhold
uses edi,esi,ebx
LOCAL dibs :DIBSECTION
LOCAL White :D
LOCAL Black :D

; Negative Threshold inverts white and black
mov D,0
mov D,0FFFFFFh

mov eax,
or eax,eax
jns >
mov D,0FFFFFFh
mov D,0
neg eax
mov ,eax
:

invoke GetObjectA,,SIZEOF DIBSECTION,offset dibs
or eax,eax
jnz >
ret
:

mov esi,
mov eax,
mul D
mov ebx,eax
shr ebx,2
sub ebx,1

.SCAN
mov eax,

movzx ecx,al ; blue
imul ecx,ecx,25
movzx edx,ah ; green
imul edx,edx,129
add edx,ecx
shr eax,16 ; red
imul eax,eax,66
add eax,edx
add eax,128
shr eax,8
add eax,16
and eax,0FFh

cmp eax,
jg >
mov eax,
mov D,eax
jmp >.NXTPIXEL
:
mov eax,
mov D,eax
.NXTPIXEL
mov ,eax
dec ebx
jns <.SCAN

mov eax,
ret
ENDF
Posted on 2006-11-18 20:41:19 by donkey
thank you very much! i'll check pixelmap also...

its not medical image processing, its for some project i could help but i cant be much more precise ... :)

a blob is likely to be quite uniform in intensity except for the border that will maybe have a (very) small gradient...

donkey , thanks, yes first thing i thought of keeping high bit(s) of the pic or converting to black/white with by comparing to a trigger value...then find the centers...then there is the problem of how many centers...

this has to be tweaked though... didnt really think of the "fill" thing thoug... thanks!... but maybe then a blob could be converted to a big blob and some garbage pixels around it, and they ll be treated as other blobs? dunno... (normally not, though)

other thing is, if i see two circular blobs partially overlapping, in a perfect world my program should be intelligent enough to see there are two blobs and return two centers... thats not very easy... but i think i'll have try things and see how it performs...

bye

Posted on 2006-11-18 22:04:29 by HeLLoWorld
pixel map object...what is it, is it this?
http://infovis.uni-konstanz.de/research/projects/pixel_based_dm/
Posted on 2006-11-18 22:09:04 by HeLLoWorld
mmh... and a floodfill algo is not trivial i think... but i should be able to figure it mysef / find some docs...



Posted on 2006-11-18 22:15:22 by HeLLoWorld
other thing is, if i see two circular blobs partially overlapping, in a perfect world my program should be intelligent enough to see there are two blobs and return two centers... thats not very easy... but i think i'll have try things and see how it performs...


No not very easy, actually very very difficult. As you implied it will probably require artificial intelligence to perform that task with any degree of usefulness. I would google arround for neural networks, edge detection, and shape recognition algorithms. There are plenty of research projects involving robotic vision that could help as well, check out the university sites. My graphics library has a simple (read very simple) edge detection routine based on BitBlt that you might find useful...

TraceEdges
Traces the edges of a 32 bit DIB section
Parameters
hBitmap = Handle to a 32 bit DIB section
Threshhold = Value from 0-255 that determines the LUMA value where the split occurs
Returns the original bitmap handle, the original image is modified

Tested GoAsm & MASM


TraceEdges FRAME hBitmap, Threshold
LOCAL hTLdc :D
LOCAL hBRdc :D
LOCAL hMasterDC :D
LOCAL memdc :D
LOCAL hdc :D
LOCAL hTLBmp :D
LOCAL hBRBmp :D
LOCAL hmemBmp :D
LOCAL hOldBmp :D
LOCAL bm :BITMAP

invoke GetDC,NULL
mov ,eax
invoke CreateCompatibleDC,
mov ,eax
invoke CreateCompatibleDC,
mov ,eax
invoke CreateCompatibleDC,
mov ,eax
invoke CreateCompatibleDC,
mov ,eax

; Get the dimensions of the bitmap
invoke GetObjectA,,SIZEOF BITMAP,offset bm

; Create 3 Monochrome bitmaps
invoke CreateBitmap,,,1,1,0
mov ,eax
invoke CreateBitmap,,,1,1,0
mov ,eax
invoke CreateBitmap,,,1,1,0
mov ,eax
invoke ReleaseDC,NULL,

; Use LithoImage to convert to B&W
invoke LithoImage,,

; Select the master bitmap into the memdc
invoke SelectObject,,
mov ,eax

; Select the main bitmap into the memdc
invoke SelectObject,,
mov ,eax

; Blt the main bitmap to make it monochrome
invoke BitBlt,,0,0,,,,0,0,SRCCOPY

invoke SetBkColor,,0FFFFFFh
invoke SetBkColor,,0FFFFFFh
invoke SetTextColor,,0h
invoke SetTextColor,,0h

; Select the 2 monochrome bitmaps into their DCs
invoke SelectObject,,
mov ,eax
invoke SelectObject,,
mov ,eax

; Fill the two monochrome bitmaps with white
invoke PatBlt,,0,0,,,WHITENESS
invoke PatBlt,,0,0,,,WHITENESS

; Blt the bitmaps in offset 1,1
mov eax,
dec eax
mov ecx,
dec ecx
invoke BitBlt,,0,0,eax,ecx,,1,1,SRCCOPY
invoke BitBlt, , 0, 0, , , \
, 0, 0, MERGEPAINT

mov eax,
dec eax
mov ecx,
dec ecx
invoke BitBlt,,1,1,eax,ecx,,0,0,SRCCOPY
invoke BitBlt, , 0, 0, , , \
, 0, 0, MERGEPAINT

invoke SelectObject,,
invoke DeleteObject,eax

; Combine the 2 images
invoke BitBlt,,0,0,, ,,0,0,SRCCOPY
invoke BitBlt,,0,0,, ,,0,0,SRCAND

invoke SelectObject,,
invoke DeleteObject,eax
invoke SelectObject,,
invoke DeleteObject,eax

invoke SelectObject,,
push eax
invoke DeleteDC,
invoke DeleteDC,
invoke DeleteDC,
invoke DeleteDC,
pop eax

RET
ENDF


FloodFill algorithms are found all over the internet in many varying types, if the blobs are expected to be small, say up to a maximum of 100 pixels or so wide you can look at a stack based one, larger than that you will need to find alternative methods.

Donkey
Posted on 2006-11-19 09:19:45 by donkey