1

I have a an image of the shape (180, 240, 3) and it will be modified according to 3 different numpy arrays that contains the location of each dimension.

So the three numpy arrays looks like this:

height_array = [
  90 148 161 165  40  77  73 108 167  59  56  65 116 165  45  50  99 163
 111 142  73  80 113 156 129  41  78  85 104  10  13  36 116 158  18 122
 170  39 155 173 172 102  53  74  81 160 167 166  21 173 148 177   2   0
   9 155 136 173  48  88  46 127 126 161  51  96  30 165 171  46 106  10
  82 118 179  95 173  93  11 116 117  25 106 164 166  87 109 112 114 179
  32  33  47  50  91  95 106 127 145 165 164 166 171  62  64  87 108 159
 130 168 174 177  35  64 102 160  43  55 105 116 166 178 107 168 164  60
 109  49 146  50  53  52  90  85 107 106 140 165 166   1  42  63  73  85
  84  82 109 112 179  48  94 118 149 134 163   7   4   5  78  64 107 111
 124 168  61 113 145  50  88  98 163  19  95 105  59  52 174  39 106 166
 171 116  28  53  72 118 175 171 163 168   2  66  93   3  66  80 144 134
  92 100 106 112 163  18  62  75  72  88  84  83  82  56  48 148 150 173
  92  59  57]
width_array = [
  13 112 212 141  23  92 127  38 143 170  99  28 127 198 168 179  48 140
  76  20 165 177  74  71  95 168 187  44  91  27 165 171  19  44   2  29
 143  80 174 137 230  28 103  94 210 141 145 196  82 141 135 140  23 176
 126 223  20 145 191 162 166  37 142 142 104   6 162 142 146 146  53 180
  55  22   9 162 146  17 114 221  34 173  95 142 139  49  54  77 130 106
  90  96  42 144  12 210  92   8 238 143 101 186 105 219 221 189  87  12
  54 195 141  29   0 176  36 142 127 183  71 172 113 140  29 142  71 171
  15 108  28  84 138 223  17  32  12  75  57  98   4 156 166  28  31 219
 225 153  71 123  96 180 236  35 219  55   3 151 169 153  96 212 117 183
 110 143 138 184 198 136  25  31 101 159  22 190 112 142 146  80 168 140
 145  67  37 173 207  59 141 141  36 139 191  37   5  48  21 168   5 158
   9  44  34  16   2   2 232 102  73   6  20  43 181 143  34  87 146 146
 193 154 143]
channel_array = [0, 0, 0, 0, 2, 1, ..., 1]

The height_array contains the y-axis location of the pixels that will be modified, while the width_array contains the x-axis location of the pixels that will be modified. channel_array contains which channel (R/G/B) will be modified. All three arrays have the same length, which is 219.

When i tried to modify the image with the following code:

image[height_array][width_array][channel_array] = 255

I get the following error:

IndexError: index 230 is out of bounds for axis 0 with size 219

I'm not sure why it's outputting this as the error. Where am I indexing the array incorrectly?

vsun92
  • 11
  • 2

1 Answers1

0

Your height_array has a length of 219, but you are trying to access position 230 in your image data, so check your indexes (You put mulitple masks on your image).

len(height_array)
219

arr = np.zeros(shape=(219,100,100))
arr[230,:,:]

IndexError: index 230 is out of bounds for axis 0 with size 219
JAdel
  • 1,309
  • 1
  • 7
  • 24