OpenCV in Python - Manipulating pixels
Question: I am using python 2.7 and OpenCV to set an image to all white pixels, but it
is not working.

Here is my code:

    
    
    import cv2
    import numpy as np
    
    image = cv2.imread("strawberry.jpg") #Load image
    
    imageWidth = image.shape[1] #Get image width
    imageHeight = image.shape[0] #Get image height
    
    xPos = 0
    yPos = 0
    
    while xPos < imageWidth: #Loop through rows
        while yPos < imageHeight: #Loop through collumns
    
            image.itemset((xPos, yPos, 0), 255) #Set B to 255
            image.itemset((xPos, yPos, 1), 255) #Set G to 255
            image.itemset((xPos, yPos, 2), 255) #Set R to 255
    
            yPos = yPos + 1 #Increment Y position by 1
        xPos = xPos + 1 #Increment X position by 1
    
    cv2.imwrite("result.bmp", image) #Write image to file
    
    print "Done"
    

I use numpy to set the pixels of the image - but the result.bmp is an exact
copy of the original image.

What am I doing wrong?

EDIT:

I know it is a bad idea to iterate over pixels, but what is the non
functioning part of my code?


Answer: rule one with opencv/python: **never** iterate over pixels, if you can avoid
it !

if you wanted to set all of the pixels to (1,2,3), it's as easy as:

    
    
    image[::] = (1,2,3)
    

for 'all white':

    
    
    image[::] = (255,255,255)
    

