views:

175

answers:

3

Hi all,

I have an image with many dots, and I would like to extract from it what is the x-y location of each dot.

I already know how to do this manually (there is a package for doing it).

However, is there some way of doing it automatically ?

(My next question will be - is there a a way, when having an image of many lines, to detect where the lines intersect/"touch each other")

Due to requests in the comments, here is an example for an image to "solve" (i.e: extract the data point locations for it)

#riddle 1 (find dots):
plot(cars, pch = 19)
#riddle 2 (find empty center circles):
plot(cars, pch = 1)
#riddle 2 (fine intersection points):
plot(cars, pch = 3)
#riddle 3 (find intersections between lines):
plot(cars, pch = 1, col = "white")
lines(stats::lowess(cars))
abline(v = c(5,10,15,20,25))

Thanks, Tal

(p.s: since I am unfamiliar with this field, I am sorry if I am using the wrong terminology or asking something too simple or complex. Is this OMR?)

+3  A: 

The Medical Imaging Task View covers general image provessing, this may be a start.

Dirk Eddelbuettel
Thank you for the link Dirk.
Tal Galili
+2  A: 

Hi TAl, Following up after Dirk, yes check the medical imaging task view. Also look at Rforge, Romain Francois has an RJImage package and another image processing package was recently registered. What you are looking for are segmentation algorithms. Your dots problem is much easier than the line problem. The first can be done with an RGB or greyscale filter, just doing some sort of radius search. Detecting linear features is harder. Once you hve the features extracted you can use a sweepline algorithm to detect intersections. EBIimage may have an example for detecting cells in the vignette.

Nicholas

Nicholas
Hi Nicholas, thank you very much for the detailed reply!Due to the comments to the question, I added an example image to try to "solve". If you might solve even the first example - it would be most useful. Thanks again, Tal
Tal Galili
+1  A: 

I think you could use package raster to extract xy coordinates from an image with specific values. Have a look at the package vignettes.

EDIT

Can you try this and tell me if it's in the ball park of what you're looking for? I hope the code with comments is quite self-explanatory. Looking forward to your answer!

library(raster)
rst <- raster(nrows = 100, ncols = 100) #create a 100x100 raster
rst[] <- round(runif(ncell(rst))) #populate raster with values, for simplicity we round them to 0 and 1
par(mfrow=c(1,2))
plot(rst) #see what you've got so far
rst.vals <- getValues(rst) #extract values from rst object
rst.cell.vals <- which(rst.vals == 1) #see which cells are 1
coords <- xyFromCell(rst, rst.cell.vals) #get coordinates of ones
rst[rst.cell.vals] <- NA #set those raster cells that are 1 to NA (you can play with rst[!rst.cell.vals] <- NA to exclude all others)
plot(rst) #a diag plot, should have only one color
Roman Luštrik
Hi Romunov, thank you for the link. I skimmed through the vignettes and couldn't find what you are talking about. On what page is what you are referring? http://cran.at.r-project.org/web/packages/raster/vignettes/Raster.pdf
Tal Galili
You basically manipulate your raster into setting all of the non-desired values to NA and extracting xy for the remaining values on the raster. That's how I do it for my project, but there could be a more elegant way I'm not familiar with yet. I admit, raster package takes some time before you get used to it and and feel its full power.
Roman Luštrik