2

I'm looking for a way to compute the similarity index between 2 files, however, I have almost 100 files for comparing. In order to make the process easier, I've started with just 10 of them. I need to load both images as matrices (image and its ground truth) for applying the method for finding the similarity coefficient. I decided to do this using the R language because I already have some data analysis working fine. So, here is the code:

library(EBImage)
library(Matrix)
    filessegIm <- list.files(path = "~/Dropbox/Codigos/original.codes/images/experiments/results", pattern = "jpg")
    filesgrndTruth <- list.files(path = "~/Dropbox/Codigos/original.codes/images/experiments/grndTruth", pattern = "jpg")
    filessegIm <- filessegIm[1:10]
    filesgrndTruth <- filesgrndTruth[1:10]

Here is the data output:

filessegIm
 [1] "ISIC_0000000_outRegions.jpg" "ISIC_0000008_outRegions.jpg"
 [3] "ISIC_0000017_outRegions.jpg" "ISIC_0000080_outRegions.jpg"
 [5] "ISIC_0000089_outRegions.jpg" "ISIC_0000211_outRegions.jpg"
 [7] "ISIC_0000243_outRegions.jpg" "ISIC_0000397_outRegions.jpg"
 [9] "ISIC_0000548_outRegions.jpg" "ISIC_0001106_outRegions.jpg"
filesgrndTruth
 [1] "ISIC_0000000_Segmentation.jpg" "ISIC_0000008_Segmentation.jpg"
 [3] "ISIC_0000017_Segmentation.jpg" "ISIC_0000080_Segmentation.jpg"
 [5] "ISIC_0000089_Segmentation.jpg" "ISIC_0000211_Segmentation.jpg"
 [7] "ISIC_0000243_Segmentation.jpg" "ISIC_0000397_Segmentation.jpg"
 [9] "ISIC_0000548_Segmentation.jpg" "ISIC_0001106_Segmentation.jpg"

Then, I'd like to load each data (actually it is the matrix of each image), using the same vector index, for applying a similarity coefficient measurement on each data. For example, compute the similarity between the matrices from image [1] "ISIC_0000000_outRegions.jpg" and image [1] "ISIC_0000000_Segmentation.jpg". I've tried this solution:

dice <- 1:10
for (f in seq_along(filessegIm)){
  segIm[f] <- filessegIm[f]
  grndTruth[f] <- filesgrndTruth[f]
  segIm[f] <- readImage(filessegIm[f])
  grndTruth[f] <- readImage(filesgrndTruth[f])
  res[f] = 2*nnzero(segIm[f]&grndTruth[f])/(nnzero(segIm[f]) + nnzero(grndTruth[f]))
}

However, it's not working properly. This for loop is working only when I use the first vector (filessegIm), I did a test commenting the lines grndTruth[f] <- filesgrndTruth[f] and grndTruth[f] <- readImage(filesgrndTruth[f]), then the for loop is working. Here is the error output:

Error in validImage(x) : object must be an array In addition: Warning messages: 1: In segIm[f] <- readImage(filessegIm[f]) : number of items to replace is not a multiple of replacement length 2: In .loadFun(files, ...) : Show Traceback Rerun with Debug Error in validImage(x) : object must be an array

I really appreciate a help with this project. Thank you!

  • Libraries: Matrix and EBImage
  • IDE: RStudio 1.1.419
  • R version: R version 3.3.3
  • platform x86_64-pc-linux-gnu
  • Operating System: Linux Debian Jessie 8.1
S4nD3r
  • 339
  • 1
  • 6

0 Answers0