BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Sam21041979
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

 

View solution in original post

5 REPLIES 5
Rick_SAS
SAS Super FREQ

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.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

 

rogerjdeangelis
Barite | Level 11

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?

Sam21041979
Calcite | Level 5

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 5 replies
  • 1631 views
  • 2 likes
  • 4 in conversation