35

Inspired by this thread How do I find Waldo with Mathematica?

I have never done image processing in R but maybe other people who have want to share...

thanks!

Community
  • 1
  • 1
Adam SO
  • 9,821
  • 8
  • 28
  • 27
  • 2
    The `EBImage` package has counterparts of at least some of the functions used in the Mathematica answer. http://www.bioconductor.org/packages/release/bioc/html/EBImage.html – Richie Cotton Dec 19 '11 at 16:35
  • 2
    `adimpro` may also be useful. http://cran.r-project.org/web/packages/adimpro/index.html – Richie Cotton Dec 19 '11 at 16:38
  • 3
    Well, there's two things going on here. First, what image processing algorithms do you want to use? Previous commenters have suggested some; I've written Sobel and Hough transforms pretty easily, etc. The other question is what format image are you playing with? FITS and TIFFs have nice "raw" pixel data while other formats may be messier. Also, you might like using imageJ better (freeware from NIH) – Carl Witthoft Dec 19 '11 at 16:55
  • 2
    why R ? Better grab octave for image-processing. More mature image processing libs and mostly matlab compatible. – Agnius Vasiliauskas Dec 19 '11 at 19:53
  • second 0x69 and Carl Witthoft. ImageJ is Java-based, very powerful and very flexible. R is not built for image processing. It might be possible to do it, exactly like it is possible to eat lobster with a hammer. – Joris Meys Dec 20 '11 at 09:46
  • @Joris: You've never tried to open a 4-pounder, eh? :-) – Carl Witthoft Dec 20 '11 at 12:38

1 Answers1

12

Here is a start, using the raster package. I don't know if I will have the time to work on the cross-correlation method used in the Mathematica version of the question, but a local standard deviation on the red parts of the image seems to spot Waldo in this case...

library(raster)
waldo = stack("/Users/Benjamin/Desktop/DepartmentStore.jpg")

r = waldo[[1]] - waldo[[2]] - waldo[[3]]
r[is.na(r)] = 0
r_mask = Which(r > 0)
r_masked = r * r_mask

focalsd = focal(r_masked, w=3, fun=sd)
plot(focalsd)
Benjamin
  • 11,560
  • 13
  • 70
  • 119
  • 4
    Please don't hesitate to un-accept this answer if a better one comes up. I was just hoping to start the flow of answers... – Benjamin Jan 18 '12 at 16:09