daily pastebin goal
55%
SHARE
TWEET

Untitled

a guest Apr 17th, 2018 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Generate k random matrix points from image matrix
  2. #The input object IMAGE is assumed to be your intensity matrix
  3. #The output is a k x 2 matrix of coordinates for each of k coordinates
  4.  
  5. GENERATE <- function(IMAGE, k) { n <- nrow(IMAGE);
  6.                                  m <- ncol(IMAGE);
  7.                                  OUTPUT <- data.frame(Row = rep(0,k),
  8.                                                       Column = rep(0,k));
  9.                                  RAND <- sample(1:(n*m), size = k, replace = TRUE,
  10.                                                 prob = as.vector(IMAGE))
  11.                                  OUTPUT$Row    <- 1 + RAND %/% n;
  12.                                  OUTPUT$Column <- RAND %% n;
  13.                                  OUTPUT }
RAW Paste Data
Top