Add helpers for working with image-magick

is_image(x)

image_rasterize2D(x)

image_mask(x, threshold = "50%", canny_geometry = "0x1+10%+30%")

image_explode(x)

image_center(x)

Arguments

x

image-magick object

threshold

to feed magick::image_threshold

canny_geometry

to feed magick::image_canny

Details

For image_mask, some "missed" objects can be avoided with large image files or by adjusting threshold and canny_edge radius.

Functions

  • is_image: tests if is of image-magick class

  • image_rasterize2D: converts image-magick to 2D raster matrix

  • image_mask: turn an inmage into a mask

  • image_explode: turn a multi-object image into multiple image with single object

  • image_center: returns image center coordinates

Examples

Momit_data("malus/malus1.jpg") %>% # you dont need magick:: if your library(magick before) magick::image_read() -> m0 m0
#> # A tibble: 1 x 7 #> format width height colorspace matte filesize density #> <chr> <int> <int> <chr> <lgl> <int> <chr> #> 1 JPEG 600 424 sRGB FALSE 59317 600x600
m1 <- m0 %>% image_mask() m1
#> # A tibble: 1 x 7 #> format width height colorspace matte filesize density #> <chr> <int> <int> <chr> <lgl> <int> <chr> #> 1 JPEG 620 444 Gray FALSE 0 600x600
mx <- m1 %>% image_explode if (FALSE) { mx } mx[1] %>% image_rasterize2D %>% algo_Conte()
#> Y X #> [1,] 55 165 #> [2,] 54 166 #> [3,] 53 166 #> [4,] 52 165 #> [5,] 51 165 #> [6,] 50 165 #> [7,] 49 165 #> [8,] 48 165 #> [9,] 47 165 #> [10,] 46 165 #> [11,] 45 165 #> [12,] 44 165 #> [13,] 43 165 #> [14,] 42 165 #> [15,] 41 165 #> [16,] 40 165 #> [17,] 39 165 #> [18,] 38 165 #> [19,] 37 165 #> [20,] 36 165 #> [21,] 35 165 #> [22,] 34 165 #> [23,] 33 165 #> [24,] 32 165 #> [25,] 31 165 #> [26,] 30 165 #> [27,] 29 165 #> [28,] 28 165 #> [29,] 27 165 #> [30,] 26 165 #> [31,] 25 165 #> [32,] 24 165 #> [33,] 23 165 #> [34,] 22 165 #> [35,] 21 165 #> [36,] 20 165 #> [37,] 19 165 #> [38,] 18 165 #> [39,] 17 165 #> [40,] 16 165 #> [41,] 15 165 #> [42,] 14 165 #> [43,] 13 165 #> [44,] 12 165 #> [45,] 11 165 #> [46,] 10 165 #> [47,] 9 165 #> [48,] 8 165 #> [49,] 7 165 #> [50,] 6 165 #> [51,] 5 165 #> [52,] 4 165 #> [53,] 3 165 #> [54,] 2 164 #> [55,] 2 163 #> [56,] 2 162 #> [57,] 2 161 #> [58,] 2 160 #> [59,] 2 159 #> [60,] 2 158 #> [61,] 2 157 #> [62,] 2 156 #> [63,] 2 155 #> [64,] 2 154 #> [65,] 2 153 #> [66,] 2 152 #> [67,] 2 151 #> [68,] 2 150 #> [69,] 2 149 #> [70,] 2 148 #> [71,] 2 147 #> [72,] 2 146 #> [73,] 2 145 #> [74,] 2 144 #> [75,] 2 143 #> [76,] 2 142 #> [77,] 2 141 #> [78,] 2 140 #> [79,] 2 139 #> [80,] 2 138 #> [81,] 2 137 #> [82,] 2 136 #> [83,] 2 135 #> [84,] 2 134 #> [85,] 2 133 #> [86,] 2 132 #> [87,] 2 131 #> [88,] 2 130 #> [89,] 2 129 #> [90,] 2 128 #> [91,] 2 127 #> [92,] 2 126 #> [93,] 2 125 #> [94,] 2 124 #> [95,] 2 123 #> [96,] 2 122 #> [97,] 2 121 #> [98,] 2 120 #> [99,] 2 119 #> [100,] 2 118 #> [101,] 2 117 #> [102,] 2 116 #> [103,] 2 115 #> [104,] 2 114 #> [105,] 2 113 #> [106,] 2 112 #> [107,] 2 111 #> [108,] 2 110 #> [109,] 2 109 #> [110,] 2 108 #> [111,] 2 107 #> [112,] 2 106 #> [113,] 2 105 #> [114,] 2 104 #> [115,] 2 103 #> [116,] 2 102 #> [117,] 2 101 #> [118,] 2 100 #> [119,] 2 99 #> [120,] 2 98 #> [121,] 2 97 #> [122,] 2 96 #> [123,] 2 95 #> [124,] 2 94 #> [125,] 2 93 #> [126,] 2 92 #> [127,] 2 91 #> [128,] 2 90 #> [129,] 2 89 #> [130,] 2 88 #> [131,] 2 87 #> [132,] 2 86 #> [133,] 2 85 #> [134,] 2 84 #> [135,] 2 83 #> [136,] 2 82 #> [137,] 2 81 #> [138,] 2 80 #> [139,] 2 79 #> [140,] 2 78 #> [141,] 2 77 #> [142,] 2 76 #> [143,] 2 75 #> [144,] 2 74 #> [145,] 2 73 #> [146,] 2 72 #> [147,] 2 71 #> [148,] 2 70 #> [149,] 2 69 #> [150,] 2 68 #> [151,] 2 67 #> [152,] 2 66 #> [153,] 2 65 #> [154,] 2 64 #> [155,] 2 63 #> [156,] 2 62 #> [157,] 2 61 #> [158,] 2 60 #> [159,] 2 59 #> [160,] 2 58 #> [161,] 2 57 #> [162,] 2 56 #> [163,] 2 55 #> [164,] 2 54 #> [165,] 2 53 #> [166,] 2 52 #> [167,] 2 51 #> [168,] 2 50 #> [169,] 2 49 #> [170,] 2 48 #> [171,] 2 47 #> [172,] 2 46 #> [173,] 2 45 #> [174,] 2 44 #> [175,] 2 43 #> [176,] 2 42 #> [177,] 2 41 #> [178,] 2 40 #> [179,] 2 39 #> [180,] 2 38 #> [181,] 2 37 #> [182,] 2 36 #> [183,] 2 35 #> [184,] 2 34 #> [185,] 2 33 #> [186,] 2 32 #> [187,] 2 31 #> [188,] 2 30 #> [189,] 2 29 #> [190,] 2 28 #> [191,] 2 27 #> [192,] 2 26 #> [193,] 2 25 #> [194,] 2 24 #> [195,] 2 23 #> [196,] 2 22 #> [197,] 2 21 #> [198,] 2 20 #> [199,] 2 19 #> [200,] 2 18 #> [201,] 2 17 #> [202,] 2 16 #> [203,] 2 15 #> [204,] 2 14 #> [205,] 2 13 #> [206,] 2 12 #> [207,] 2 11 #> [208,] 2 10 #> [209,] 2 9 #> [210,] 2 8 #> [211,] 2 7 #> [212,] 2 6 #> [213,] 2 5 #> [214,] 2 4 #> [215,] 2 3 #> [216,] 3 2 #> [217,] 4 2 #> [218,] 5 2 #> [219,] 6 2 #> [220,] 7 2 #> [221,] 8 2 #> [222,] 9 2 #> [223,] 10 2 #> [224,] 11 2 #> [225,] 12 2 #> [226,] 13 2 #> [227,] 14 2 #> [228,] 15 2 #> [229,] 16 2 #> [230,] 17 2 #> [231,] 18 2 #> [232,] 19 2 #> [233,] 20 2 #> [234,] 21 2 #> [235,] 22 2 #> [236,] 23 2 #> [237,] 24 2 #> [238,] 25 2 #> [239,] 26 2 #> [240,] 27 2 #> [241,] 28 2 #> [242,] 29 2 #> [243,] 30 2 #> [244,] 31 2 #> [245,] 32 2 #> [246,] 33 2 #> [247,] 34 2 #> [248,] 35 2 #> [249,] 36 2 #> [250,] 37 2 #> [251,] 38 2 #> [252,] 39 2 #> [253,] 40 2 #> [254,] 41 2 #> [255,] 42 2 #> [256,] 43 2 #> [257,] 44 2 #> [258,] 45 2 #> [259,] 46 2 #> [260,] 47 2 #> [261,] 48 2 #> [262,] 49 2 #> [263,] 50 2 #> [264,] 51 2 #> [265,] 52 2 #> [266,] 53 2 #> [267,] 54 2 #> [268,] 55 2 #> [269,] 56 2 #> [270,] 57 2 #> [271,] 58 2 #> [272,] 59 2 #> [273,] 60 2 #> [274,] 61 2 #> [275,] 62 2 #> [276,] 63 2 #> [277,] 64 2 #> [278,] 65 2 #> [279,] 66 2 #> [280,] 67 2 #> [281,] 68 2 #> [282,] 69 2 #> [283,] 70 2 #> [284,] 71 2 #> [285,] 72 2 #> [286,] 73 2 #> [287,] 74 2 #> [288,] 75 2 #> [289,] 76 2 #> [290,] 77 2 #> [291,] 78 2 #> [292,] 79 2 #> [293,] 80 2 #> [294,] 81 2 #> [295,] 82 2 #> [296,] 83 2 #> [297,] 84 2 #> [298,] 85 2 #> [299,] 86 2 #> [300,] 87 2 #> [301,] 88 2 #> [302,] 89 2 #> [303,] 90 2 #> [304,] 91 2 #> [305,] 92 2 #> [306,] 93 2 #> [307,] 94 2 #> [308,] 95 2 #> [309,] 96 2 #> [310,] 97 2 #> [311,] 98 2 #> [312,] 99 2 #> [313,] 100 2 #> [314,] 101 2 #> [315,] 102 2 #> [316,] 103 2 #> [317,] 104 2 #> [318,] 105 2 #> [319,] 106 2 #> [320,] 107 2 #> [321,] 108 3 #> [322,] 108 4 #> [323,] 108 5 #> [324,] 108 6 #> [325,] 108 7 #> [326,] 108 8 #> [327,] 108 9 #> [328,] 108 10 #> [329,] 108 11 #> [330,] 108 12 #> [331,] 108 13 #> [332,] 108 14 #> [333,] 108 15 #> [334,] 108 16 #> [335,] 108 17 #> [336,] 108 18 #> [337,] 108 19 #> [338,] 108 20 #> [339,] 108 21 #> [340,] 108 22 #> [341,] 108 23 #> [342,] 108 24 #> [343,] 108 25 #> [344,] 108 26 #> [345,] 108 27 #> [346,] 108 28 #> [347,] 108 29 #> [348,] 108 30 #> [349,] 108 31 #> [350,] 108 32 #> [351,] 108 33 #> [352,] 108 34 #> [353,] 108 35 #> [354,] 108 36 #> [355,] 108 37 #> [356,] 108 38 #> [357,] 108 39 #> [358,] 108 40 #> [359,] 108 41 #> [360,] 108 42 #> [361,] 108 43 #> [362,] 108 44 #> [363,] 108 45 #> [364,] 108 46 #> [365,] 108 47 #> [366,] 108 48 #> [367,] 108 49 #> [368,] 108 50 #> [369,] 108 51 #> [370,] 108 52 #> [371,] 108 53 #> [372,] 108 54 #> [373,] 108 55 #> [374,] 108 56 #> [375,] 108 57 #> [376,] 108 58 #> [377,] 108 59 #> [378,] 108 60 #> [379,] 108 61 #> [380,] 108 62 #> [381,] 108 63 #> [382,] 108 64 #> [383,] 108 65 #> [384,] 108 66 #> [385,] 108 67 #> [386,] 108 68 #> [387,] 108 69 #> [388,] 108 70 #> [389,] 108 71 #> [390,] 108 72 #> [391,] 108 73 #> [392,] 108 74 #> [393,] 108 75 #> [394,] 108 76 #> [395,] 108 77 #> [396,] 108 78 #> [397,] 108 79 #> [398,] 108 80 #> [399,] 108 81 #> [400,] 108 82 #> [401,] 108 83 #> [402,] 108 84 #> [403,] 108 85 #> [404,] 108 86 #> [405,] 108 87 #> [406,] 108 88 #> [407,] 108 89 #> [408,] 108 90 #> [409,] 108 91 #> [410,] 108 92 #> [411,] 108 93 #> [412,] 108 94 #> [413,] 108 95 #> [414,] 108 96 #> [415,] 108 97 #> [416,] 108 98 #> [417,] 108 99 #> [418,] 108 100 #> [419,] 108 101 #> [420,] 108 102 #> [421,] 108 103 #> [422,] 108 104 #> [423,] 108 105 #> [424,] 108 106 #> [425,] 108 107 #> [426,] 108 108 #> [427,] 108 109 #> [428,] 108 110 #> [429,] 108 111 #> [430,] 108 112 #> [431,] 108 113 #> [432,] 108 114 #> [433,] 108 115 #> [434,] 108 116 #> [435,] 108 117 #> [436,] 108 118 #> [437,] 108 119 #> [438,] 108 120 #> [439,] 108 121 #> [440,] 108 122 #> [441,] 108 123 #> [442,] 108 124 #> [443,] 108 125 #> [444,] 108 126 #> [445,] 108 127 #> [446,] 108 128 #> [447,] 108 129 #> [448,] 108 130 #> [449,] 108 131 #> [450,] 108 132 #> [451,] 108 133 #> [452,] 108 134 #> [453,] 108 135 #> [454,] 108 136 #> [455,] 108 137 #> [456,] 108 138 #> [457,] 108 139 #> [458,] 108 140 #> [459,] 108 141 #> [460,] 108 142 #> [461,] 108 143 #> [462,] 108 144 #> [463,] 108 145 #> [464,] 108 146 #> [465,] 108 147 #> [466,] 108 148 #> [467,] 108 149 #> [468,] 108 150 #> [469,] 108 151 #> [470,] 108 152 #> [471,] 108 153 #> [472,] 108 154 #> [473,] 108 155 #> [474,] 108 156 #> [475,] 108 157 #> [476,] 108 158 #> [477,] 108 159 #> [478,] 108 160 #> [479,] 108 161 #> [480,] 108 162 #> [481,] 108 163 #> [482,] 108 164 #> [483,] 107 165 #> [484,] 106 165 #> [485,] 105 165 #> [486,] 104 165 #> [487,] 103 165 #> [488,] 102 165 #> [489,] 101 165 #> [490,] 100 165 #> [491,] 99 165 #> [492,] 98 165 #> [493,] 97 165 #> [494,] 96 165 #> [495,] 95 165 #> [496,] 94 165 #> [497,] 93 165 #> [498,] 92 165 #> [499,] 91 165 #> [500,] 90 165 #> [501,] 89 165 #> [502,] 88 165 #> [503,] 87 165 #> [504,] 86 165 #> [505,] 85 165 #> [506,] 84 165 #> [507,] 83 165 #> [508,] 82 165 #> [509,] 81 165 #> [510,] 80 165 #> [511,] 79 165 #> [512,] 78 165 #> [513,] 77 165 #> [514,] 76 165 #> [515,] 75 165 #> [516,] 74 165 #> [517,] 73 165 #> [518,] 72 165 #> [519,] 71 165 #> [520,] 70 165 #> [521,] 69 165 #> [522,] 68 165 #> [523,] 67 165 #> [524,] 66 165 #> [525,] 65 165 #> [526,] 64 165 #> [527,] 63 165 #> [528,] 62 165 #> [529,] 61 165 #> [530,] 60 165 #> [531,] 59 165 #> [532,] 58 165 #> [533,] 57 165 #> [534,] 56 165 #> [535,] 55 165