0

i am trying to create a mask for analyzing some of my images. in this mask i need to have at least 500 different numbers. but i can just use an ndarray without changing it into an image because i use opencv in the process of creating the mask.. so if a number is larger than 255 it just change it to (number - 255).

def create_mask(x=20, y=12, l=480):
    s = int(l / y)
    lin_mask = np.zeros([l*2, s*x], np.uint8)
    color = 0
    for i in range(y*2):
        for j in range(x):
            lin_mask[i*s:(i+1)*s, j*s:(j+1)*s] = np.ones([s, s], np.uint8)*color
            color = color + 1
    m = cv2.warpPolar(lin_mask, (l*2, l*2), (l, l), l, cv2.WARP_INVERSE_MAP)
    t = int(l/2)
    m = m[t: t+l, t:t+l]
    return m
Eshaka
  • 974
  • 1
  • 14
  • 38
  • 3
    I don't get, why you just can't use `np.uint16` instead of `np.uint8` in both `lin_mask` assignments!? Switching to that, `m` has a maximum of `470`. – HansHirse Oct 14 '19 at 11:42
  • To follow up on what @HansHirse has said, [this answer](https://stackoverflow.com/a/7587819/11301900) may be of use. – AMC Oct 14 '19 at 21:36
  • thanks guys, but can someone please explain me why the max is 470 – Eshaka Oct 15 '19 at 00:29
  • Unfortunately, I’m not sure what he meant. @HansHirse is the only one who can give you an answer. – AMC Oct 16 '19 at 23:52
  • @Eshaka Just debug/inspect your code at runtime. When running your code as is, the maximum value in `m` is `255`. In fact, there can't be greater values than `255`, since you use `np.uint8`. If we switch to `np.uint16`, running your code then shows, that the maximum in `m` is `470`. WHY the maximum is `470`, I can't tell. It's YOUR code, I haven't analyzed what it actually does. That's up to you!? – HansHirse Oct 17 '19 at 05:25

0 Answers0