0

I´m currently working on normalizing ct-scans (x, y, layer). Normalizing the first two dimensions is simple using cv2.reshape, but the third dimension... My idea is to flatten the first two dimensions to get a 2d-numpy-array. If I do the reshape to (x * y) for each layer and reshape it back to (x, y) I get a completely different image. I have a img of a lung in the beginning and lines of different gray values afterwords.

test = cv2.resize(img, (img.shape[0] * img.shape[1], 1), interpolation=cv2.INTER_LINEAR)
test = cv2.resize(test, (159, 159), interpolation=cv2.INTER_LINEAR)
self.print_prediction(test, cv2.resize(temp2_masks[:, 0], (159, 159)),
                                  color=False, shape=(159, 159))

I'm sure it's some kind of simple mistake, but I don't see it. So I would be very grateful for help.

Dennis182
  • 13
  • 3

1 Answers1

0

The cv2.resize function does not reshape your array. It actually resizes the image. Your first line is squashing your image horizontally while expanding it a lot vertically. The values are not preserved at all.

Use numpy.reshape to reshape your arrays instead.

Sunreef
  • 4,452
  • 21
  • 33