MomX / Momocs

:dove: Morphometrics using R
http://momx.github.io/Momocs/
51 stars 19 forks source link

import_jpg auto.notcentered = FALSE doesn't seem to work #165

Closed benmarwick closed 8 years ago

benmarwick commented 8 years ago

I'm really enjoying the import_jpg functions, but I can't seem to get auto.notcentered = FALSE to work. Here's a self-contained example:

library(magick)
frink.png <- image_read("https://jeroenooms.github.io/images/frink.png")

image_write(frink.png, paste0(getwd(),"/frink.jpg"), format = 'jpeg')

import_jpg1("frink.jpg", auto.notcentered = FALSE)

I just get this output, no locate option:

       [,1] [,2]
  [1,]  112  224
  [2,]  111  223
  [3,]  110  223
  [4,]  109  224
  [5,]  109  225
  [6,]  110  226
  [7,]  109  227
  [8,]  109  228
  [9,]  109  229
 [10,]  109  230
 [11,]  110  231
 [12,]  110  232
 [13,]  111  233
 [14,]  112  234
 [15,]  113  234
 [16,]  114  235
 [17,]  115  235
 [18,]  116  235
 [19,]  117  236
 [20,]  118  235
 [21,]  119  235
 [22,]  120  235
 [23,]  121  235
 [24,]  122  235
 [25,]  123  235
 [26,]  124  234
 [27,]  125  234
 [28,]  126  233
 [29,]  127  233
 [30,]  128  232
 [31,]  129  231
 [32,]  130  231
 [33,]  131  230
 [34,]  132  229
 [35,]  133  228
 [36,]  134  227
 [37,]  135  226
 [38,]  136  225
 [39,]  136  224
 [40,]  135  223
 [41,]  134  224
 [42,]  133  225
 [43,]  132  226
 [44,]  131  227
 [45,]  130  228
 [46,]  129  229
 [47,]  128  229
 [48,]  127  230
 [49,]  126  231
 [50,]  125  231
 [51,]  124  232
 [52,]  123  232
 [53,]  122  232
 [54,]  121  233
 [55,]  120  233
 [56,]  119  233
 [57,]  118  233
 [58,]  117  233
 [59,]  116  233
 [60,]  115  232
 [61,]  114  232
 [62,]  113  232
 [63,]  112  231
 [64,]  112  230
 [65,]  112  229
 [66,]  112  228
 [67,]  112  227
 [68,]  113  226
 [69,]  114  225
 [70,]  115  226
 [71,]  116  226
 [72,]  117  226
 [73,]  118  227
 [74,]  119  227
 [75,]  120  227
 [76,]  121  227
 [77,]  122  226
 [78,]  121  225
 [79,]  120  224
 [80,]  119  224
 [81,]  118  224
 [82,]  117  224
 [83,]  116  223
 [84,]  115  223
 [85,]  114  222
 [86,]  113  222
 [87,]  112  221
 [88,]  111  220
 [89,]  111  219
 [90,]  111  218
 [91,]  111  217
 [92,]  111  216
 [93,]  112  215
 [94,]  112  214
 [95,]  113  214
 [96,]  114  214
 [97,]  115  215
 [98,]  116  215
 [99,]  117  216
[100,]  118  216
[101,]  119  216
[102,]  120  216
[103,]  121  217
[104,]  122  216
[105,]  123  215
[106,]  122  214
[107,]  121  214
[108,]  120  214
[109,]  119  214
[110,]  118  213
[111,]  117  213
[112,]  116  212
[113,]  115  212
[114,]  114  211
[115,]  113  210
[116,]  112  209
[117,]  112  208
[118,]  112  207
[119,]  112  206
[120,]  113  205
[121,]  113  204
[122,]  114  204
[123,]  115  203
[124,]  115  202
[125,]  114  201
[126,]  113  201
[127,]  112  202
[128,]  111  203
[129,]  111  204
[130,]  110  205
[131,]  110  206
[132,]  110  207
[133,]  110  208
[134,]  110  209
[135,]  110  210
[136,]  111  211
[137,]  111  212
[138,]  110  213
[139,]  109  214
[140,]  109  215
[141,]  109  216
[142,]  108  217
[143,]  108  218
[144,]  108  219
[145,]  109  220
[146,]  109  221
[147,]  110  222
[148,]  111  223
[149,]  112  224
> devtools::session_info()
Session info ----------------------------------------------------------
 setting  value                       
 version  R version 3.3.1 (2016-06-21)
 system   x86_64, mingw32             
 ui       RStudio (1.0.5)             
 language (EN)                        
 collate  English_Australia.1252      
 tz       America/Los_Angeles         
 date     2016-09-26                  

Packages --------------------------------------------------------------
 package    * version   date       source                           
 ape          3.5       2016-05-24 CRAN (R 3.3.1)                   
 assertthat   0.1       2013-12-06 CRAN (R 3.2.2)                   
 coda         0.18-1    2015-10-16 CRAN (R 3.2.2)                   
 colorspace   1.2-6     2015-03-11 CRAN (R 3.2.2)                   
 curl         2.1       2016-09-22 CRAN (R 3.3.1)                   
 DBI          0.5-1     2016-09-10 CRAN (R 3.3.1)                   
 deSolve      1.13      2016-03-01 Github (cran/deSolve@cc78bb2)    
 devtools     1.12.0    2016-06-24 CRAN (R 3.3.1)                   
 digest       0.6.10    2016-08-02 CRAN (R 3.3.1)                   
 dplyr      * 0.5.0     2016-06-24 CRAN (R 3.3.1)                   
 geiger       2.0.6     2015-09-07 Github (cran/geiger@87d863b)     
 geometry     0.3-6     2015-09-09 Github (cran/geometry@2e602af)   
 geomorph     3.0.2     2016-07-19 CRAN (R 3.3.1)                   
 ggplot2    * 2.1.0     2016-03-01 CRAN (R 3.3.1)                   
 gtable       0.2.0     2016-02-26 CRAN (R 3.2.4)                   
 jpeg         0.1-8     2014-01-23 CRAN (R 3.2.2)                   
 lattice      0.20-33   2015-07-14 CRAN (R 3.2.2)                   
 magic        1.5-6     2013-11-20 Github (cran/magic@2ecbf90)      
 magick     * 0.3       2016-09-06 CRAN (R 3.3.1)                   
 magrittr     1.5       2014-11-22 CRAN (R 3.3.1)                   
 MASS         7.3-45    2016-04-21 CRAN (R 3.3.1)                   
 Matrix       1.2-6     2016-05-02 CRAN (R 3.3.1)                   
 memoise      1.0.0     2016-01-29 CRAN (R 3.2.5)                   
 Momocs     * 1.0.4     2016-05-04 Github (vbonhomme/Momocs@1aaa859)
 munsell      0.4.3     2016-02-13 CRAN (R 3.2.4)                   
 mvtnorm      1.0-5     2016-02-02 CRAN (R 3.2.3)                   
 nlme         3.1-128   2016-05-10 CRAN (R 3.3.1)                   
 plyr         1.8.4     2016-06-08 CRAN (R 3.3.1)                   
 purrr      * 0.2.2     2016-06-18 CRAN (R 3.3.1)                   
 R6           2.1.3     2016-08-19 CRAN (R 3.3.1)                   
 Rcpp         0.12.7    2016-09-05 CRAN (R 3.3.1)                   
 readr      * 1.0.0     2016-08-03 CRAN (R 3.3.1)                   
 reshape2     1.4.1     2014-12-06 CRAN (R 3.2.2)                   
 rgl          0.95.1441 2016-01-04 CRAN (R 3.2.5)                   
 scales       0.4.0     2016-02-26 CRAN (R 3.2.4)                   
 sp           1.2-3     2016-04-14 Github (cran/sp@a7c10d3)         
 stringi      1.1.1     2016-05-27 CRAN (R 3.3.0)                   
 stringr      1.1.0     2016-08-19 CRAN (R 3.3.1)                   
 subplex      1.1-6     2015-07-11 Github (cran/subplex@2b17590)    
 tibble     * 1.2       2016-08-26 CRAN (R 3.3.1)                   
 tidyr      * 0.6.0     2016-08-12 CRAN (R 3.3.1)                   
 tidyverse  * 1.0.0     2016-09-09 CRAN (R 3.3.1)                   
 withr        1.0.2     2016-06-20 CRAN (R 3.3.0) 
vbonhomme commented 8 years ago

Hi there, thanks for pointing this. I think the problem is that frink is not a "mask", black pixels on white background...(see Momocs vignette for some details) that's quite boring, and I have a mind (for like 4 years now) coupling Momocs with a segmenting tool that would avoid for some cases the GIMP/Photoshop/ImageJ step... Here is a picture that illustrate what I call a mask:

beer_deusventrue

all the best

v

benmarwick commented 8 years ago

ok, thanks for clarifying that! My actual use-case was a mask, but not a very clean one, with lots of dark spots in the background. I cleaned it up and it has worked find. But it's good to know from you this is only for masks

Yes, it's tricky to avoid some manual processing before working the image in R. I see there have been some efforts to work with imagej and R, but nothing current/working that I can see.

Thanks again!