-1

I try to copy a range of pixel rows from one .png image (RGB mode) into another one. With the red and green components it works just fine. But it seems that the blue component will never be copied, so that the resulting image has different color than the original one. My code looks like below:

row = 200
width = 1000
color = 3
for r in range(100, 150):
    for c in range(width):
        for cl in range(color):
            imar1[row][c][cl] = imar[r][c][cl]
    row += 1

imar is the numpy array of the original image, and imar1 that of the new one which was initialized to a white image (all pixels are white, i.e. (255,255,255)). The resulting image has 255 for the blue component of all pixels. Can someone give me hint on the reason or solution? Many thanks in advance!

Weichao

W. Wang
  • 7
  • 2
  • Have you checked that the values in `imar` are right? – Michael Butscher May 29 '23 at 00:29
  • Your [mcve] is incomplete - no `import` statements and no images, no indication of shape or `dtype` of arrays - so it is not easy to help you properly. Have you read this? https://stackoverflow.com/a/52307690/2836621 – Mark Setchell May 29 '23 at 07:24
  • Well, I've written a very simple program to copy certain rows of an image into another, and it works quite normally without loosing the blue component. I must first search where the problem might be. I'll come back to this thread after I've found the problem. – W. Wang May 30 '23 at 08:48
  • Mmmm… the general idea is that we try to help you. – Mark Setchell May 30 '23 at 09:29

1 Answers1

0

I've found the problem. In my program I've not assigned the value 3 to the variable color, and in the part before in the program the color has reached the value of 2, so that always only the first two components are copied. Excuse for the confusion.

W. Wang
  • 7
  • 2