Answer the question
In order to leave comments, you need to log in
What is the correct way to convert a gray image to an array?
I'm doing an experiment. I take the first image from the MNIST database
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 18 18 18 126 136 175 26 166 255 247 127 0 0 0 0 0 0 0 0 0 0 0 0 30 36 94 154 170 253 253 253 253 253 225 172 253 242 195 64 0 0 0 0 0 0 0 0 0 0 0 49 238 253 253 253 253 253 253 253 253 251 93 82 82 56 39 0 0 0 0 0 0 0 0 0 0 0 0 18 219 253 253 253 253 253 198 182 247 241 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 80 156 107 253 253 205 11 0 43 154 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 14 1 154 253 90 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 139 253 190 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 11 190 253 70 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 35 241 225 160 108 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 81 240 253 253 119 25 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 45 186 253 253 150 27 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 16 93 252 253 187 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 249 253 249 64 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 46 130 183 253 253 207 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 39 148 229 253 253 253 250 182 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 24 114 221 253 253 253 253 201 78 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 23 66 213 253 253 253 253 198 81 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 18 171 219 253 253 253 253 195 80 9 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 55 172 226 253 253 253 253 244 133 11 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 136 253 253 253 212 135 132 16 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
[0 0 1 1 3 5 3 0 0 0 0 1 1 0 0 1 0 0 4 8 0 17 0 0 0 0 0 0 0 2 2 0 0 0 0 0 0 0 0 1 1 1 1 3 0 0 1 0 0 0 9 5 0 0 0 0 1 2 3 0 0 0 0 2 6 5 3 1 0 0 0 0 7 2 6 10 17 0 1 0 0 0 0 0 3 0 0 2 2 0 1 4 1 3 2 0 0 2 3 1 0 0 0 0 0 0 0 12 0 0 0 0 5 0 0 2 5 1 0 0 0 2 2 0 0 1 0 0 5 0 18 0 16 4 0 12 0 0 0 0 6 0 0 1 2 0 0 0 0 0 5 6 12 22 24 19 113 158 172 25 151 255 255 120 0 0 0 0 3 0 0 2 0 0 1 15 28 55 92 131 177 223 251 255 255 250 211 176 255 245 187 62 0 0 0 0 0 0 1 4 0 0 12 37 235 248 255 254 255 255 255 249 250 251 105 84 75 52 46 0 0 0 0 0 0 0 0 0 0 2 5 8 214 255 251 238 255 245 210 180 249 247 5 1 0 7 0 4 0 0 0 0 0 0 0 0 0 2 4 6 83 149 104 255 255 200 4 0 41 140 3 0 7 10 0 11 0 0 0 0 1 0 0 0 0 1 2 4 8 19 0 157 236 94 5 0 0 26 0 2 0 5 0 0 0 0 0 0 2 1 0 0 0 0 0 1 0 0 10 139 255 182 22 0 12 0 1 9 0 0 12 0 0 0 0 0 1 1 0 0 0 0 0 0 8 0 10 0 185 255 54 0 0 0 20 1 3 0 0 5 0 0 0 0 0 0 0 0 0 0 0 0 0 5 0 11 52 246 225 167 108 12 0 0 11 0 0 4 0 0 0 0 0 0 0 0 0 0 0 0 3 5 10 0 0 61 255 248 255 108 25 1 0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 2 0 8 9 45 181 255 246 150 23 0 3 0 6 0 0 0 0 6 2 0 3 0 0 4 0 0 4 3 0 0 0 2 11 92 255 255 177 4 0 4 0 0 0 0 0 0 0 0 6 0 0 0 8 9 0 0 11 7 3 8 4 0 255 254 230 73 1 0 13 0 0 0 0 6 10 4 0 0 15 10 0 4 8 0 0 2 0 41 131 191 239 252 224 0 5 11 0 0 0 0 0 0 0 4 5 3 0 0 8 0 0 12 5 29 140 237 243 253 247 255 182 0 0 0 18 0 0 0 0 0 0 6 0 5 14 0 1 12 4 16 108 225 255 245 255 255 209 69 9 4 0 0 0 0 0 0 0 11 5 7 0 0 1 0 17 3 84 198 253 253 255 245 190 72 15 0 0 0 6 17 0 0 0 0 0 6 0 0 12 12 0 25 158 231 243 247 255 255 193 83 16 0 0 21 4 6 6 0 4 0 0 0 0 0 5 4 0 62 177 214 255 248 252 255 233 130 24 0 0 0 7 0 8 0 0 15 0 0 0 0 0 2 0 0 20 125 240 255 246 198 145 118 22 11 0 0 3 0 0 0 0 0 0 0 0 0 0 0 0 3 11 7 0 0 9 6 0 13 0 20 0 4 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 2 0 0 6 0 0 2 0 1 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 17 0 0 0 0 0 0 0 13 12 2 3 0 5 0 5 0 0 0 0 0 0 0 0 0 0 0 0]
Answer the question
In order to leave comments, you need to log in
You have encoded a binary uncompressed image (where each byte or group of bytes, depending on how many channels is a single pixel) with a jpeg codec into a lossy compressed format. This format has a header and its pixels are represented there as an array of bytes, everything is more complicated there.
But the format itself is a byte string, which you now for some reason turn into an array ...
Convert JHPEG back to a bitmap and you will have the same array as the original one. Possibly almost the same as you have quality loss and some pixels may be slightly overcolored.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question