Reputation: 31
I'm using the R package Momocs
to compare outlines of shapes I've traced in ImageJ and saved as binary image tiffs. For example: one outline of snail teeth. Momocs requires a matrix of X and Y coordinates, and I'm having trouble converting from image to coordinates.
On the one hand: ImageJ has an option to Save As... XY Coordinates, but this only works on a selection. I can use the wand tool to select the outline, but it encircles the one-pixel-wide outlines, e.g. a straight line would have coordinates of a long rectangle, describing both sides of the line. This makes me see my snail teeth in double-vision (image example of one tooth close-up) and may adversely affect analysis.
On the other hand: Momocs has an import_jpg1
command, but when I convert my images to jpegs (or make jpegs from scratch), they end up with light-colored pixels as noise around the outlines. I tried the packages tiff
and rtiff
, but their outputs are not XY coordinates of the black parts of the tiff, and I'm not familiar enough with the outputs to understand how I might convert them to XY coordinates.
Can anyone help me do one (or multiple!) of these things:
Momocs
can readtiff
or rtiff
into a format
Momocs
can readThanks in advance for any help!
Upvotes: 1
Views: 727
Reputation: 1545
You can easily extract the matrix of XY coordinates of pixels meeting certain criteria with R's function which
by specifying arr.ind=TRUE
. To illustrate this approach I use the Bioconductor package EBImage to directly load the sample PNG file from the provided URL. readImage
is a wrapper for the functions provided in R packages jpeg, png and tiff, so apart from PNGs it also opens JPEG and TIFF files.
### Install EBImage
# source("https://bioconductor.org/biocLite.R")
# biocLite("EBImage")
img <- EBImage::readImage("https://i.sstatic.net/ZFTxu.png")
mat <- which(img==0, arr.ind=TRUE, useNames=FALSE)
head(mat)
## [,1] [,2]
## [1,] 121 53
## [2,] 120 54
## [3,] 118 55
## [4,] 119 55
## [5,] 117 56
## [6,] 116 57
EBImage offers a wide range of tools for working with image data in R which might be of interest to you, such as functions for manipulating, filtering and displaying images. See the package vignette for an overview.
Upvotes: 1