2016-10-11 63 views
0

我正在使用處理模式在Python模式下加載圖像並對其進行計算。總的想法是:Py處理像素[]陣列不包含大圖像中的所有像素

def setup(): 
    global maxx, maxy 
    maxx = 0 
    maxy = 0 

    # load the image 
    global img 
    img = loadImage("img.jpg"); 

    maxx = img.width 
    maxy = img.height 

def draw(): 
    image(img, 0, 0); 

def mousePressed(): 
    calc() 

def calc(): 
    height = int(img.height) 
    width = int(img.width) 
    print "width: " + `width` 
    print "height: " + `height` 
    print "width*height: " + `width*height` 

    # iterate over the input image 
    loadPixels() 
    print "length of pixels array: " + `len(pixels)` 

    # ... do stuff with the image 

爲1920×1200數量級的較小的圖像,將「寬×高」和「像素陣列的長度」是相同的。對於像3025×2009這樣的大型圖像,像素陣列的長度要小得多。對於3025 X 2009的例子的區別在於:
寬*高:6077225 長度的像素陣列組成:3944600

任何想法可能什麼呢?

+0

會發生什麼,如果你再嘗試與像素創建一個新的形象更多的研究後更新這個答案陣列?這個圖像是什麼樣的? –

+0

@KevinWorkman感謝您的回覆。在試圖將像素寫入像你所建議的圖像,我發現更明確地解決了這個問題。 img.loadPixels() print「pixels of pixel array:」+'len(img.pixels)' – raf

回答

1

在調試中,我發現了這個問題。調用loadPixel在IMG得到正確的像素...

def calc(): 
    height = int(img.height) 
    width = int(img.width) 
    print "width: " + `width` 
    print "height: " + `height` 
    print "width*height: " + `width*height` 

    # iterate over the input image 
    img.loadPixels() 
    print "length of pixels array: " + `len(img.pixels)` 

我會在loadPixels()