Statistical programming, matrix languages, and more

Image processing

Reply
New Contributor
Posts: 2

Image processing

Dear Everybody,

 

I applied some image processing technics in order to get a more focussed configuration.

 

I get something like this:

 

 Capture.PNG

 

This photo consist of a matrix of 0 (black) and 1 (white).

My objective is identify all the white circles and to fill them with white color (transform 0's to 1's).

Do you think it is possible to detect the circles and then do this action?

Thanks a lot ofr your help.

Krs,

Samir

SAS Super FREQ
Posts: 3,220

Re: Image processing

I think this is a difficult task. There have been research papers written in computational geometry and computer vision that address this kind of problem, but there are mathematical as well and computational issues.

 

There are a few reasons it is hard. First, the pixels are discrete, so you have to define rules for recognizing a closed polygon when the edges are pixels. Second, it is not clear what is inside or outside. Third, this is a problem of global geometry, not local geometry.

 

For the first problem, consider the following region:

010

101

010

You would have to define a rule whether to change the middle cell to white,

 

Second, consider the following pixels: 

11111111111

1001001001

1001111001

1000000001

11111111111

 

These pixels approximate a self-intersecting loop, but also two nested circles, like this

Untitled.png

It is not clear which zeros should be changed to 1s.

 

The situation is even worse when some of the pixels touch the boundary, as yours do. Then it is not clear where the INSIDE of the curve is.  For example, can you find the inside of the inside of the following image?

download.jpg

 

In summary, I think you should discuss this problem with a computer scientist who might know if there is specialized software. I suspect it will be daunting to write an algorithm yourself in a general-purpose language like SAS/IML.

Esteemed Advisor
Esteemed Advisor
Posts: 6,670

Re: Image processing

Firstly that image contains open circles, how would you handle that, or just lines?

 

SAS wouldn't be the way I would choose to do this.  

What I would do is this (and you may be able to batch mode this):
Get a proper image editing package - GIMP for instance.

Use this package to create another layer to the image, fill the image with white - i.e. so the circles would still be black but everything else would be white. 

Use the two layers to create a merged image, i.e. if black in base layer, and black in top layer then black, if black in top layer then black, else white.  Maybe mask top as white is transparent:

https://docs.gimp.org/en/gimp-image-merge-layers.html

 

However this is outside the scope of this forum.

 

Esteemed Advisor
Esteemed Advisor
Posts: 6,670

Re: Image processing

Firstly that image contains open circles, how would you handle that, or just lines?

 

SAS wouldn't be the way I would choose to do this.  

What I would do is this (and you may be able to batch mode this):
Get a proper image editing package - GIMP for instance.

Use this package to create another layer to the image, fill the image with white - i.e. so the circles would still be black but everything else would be white. 

Use the two layers to create a merged image, i.e. if black in base layer, and black in top layer then black, if black in top layer then black, else white.  Maybe mask top as white is transparent:

https://docs.gimp.org/en/gimp-image-merge-layers.html

 

However this is outside the scope of this forum.

 

Valued Guide
Posts: 505

Re: Image processing

This tends to be a very sophisticated problem, not easily soled by a non-programming(EG server) oriented system like SAS.

 

I have poseted a python maze image soltion in SAS-L. However I would investigate

 

http://www.pyimagesearch.com/2014/07/21/detecting-circles-images-using-opencv-hough-circles/

 

for circles.

 

I think it is doable in python. I have also posted an interface to python from SAS. As a side note WPS has a python interface. I don't think SAS should waste resources on image processing because Python has easly usable packages?

New Contributor
Posts: 2

Re: Image processing

Dear Everybody,

 

Thanks a lot for your suggestions.

 

I will do some investigations according to your replies and go back to you.

 

Have a nice day,

 

Samir

Post a Question
Discussion Stats
  • 5 replies
  • 148 views
  • 2 likes
  • 4 in conversation