2017-06-18 2 views
0

Ich frage mich, ist es möglich, Bild in Blöcke zum Beispiel 8x8 Blöcke (64 pixels per block) zu teilen und Histogramm-Funktion für jeden Block und speichern Ergebnisse in ein neues Bild nicht zu separaten Bildern?F: Teilen Sie Bild in Blöcke Python

def apply_histogram(block): 
    h, b = np.histogram(block.flatten(), 256, normed=True) 
    cdf = h.cumsum() 
    cdf = 255 * cdf/cdf[-1] 
    return np.interp(block.flatten(), b[:-1], cdf).reshape(block.shape) 
+0

Mögliche Duplikat von [Wie Bild in mehrere Teile in Python nach Split] (https://stackoverflow.com/questions/5953373/How-To-Split-Bild-in-mehrere-Stücke-in-Python) – moritzg

+0

Ich nicht w Ameise, um das Bild zu teilen. Und ich möchte Funktion auf Bild nicht sofort anwenden, ich will Funktion in Bild auf jeden 8x8 Block anwenden. – Streem

Antwort

2

Warum nicht durch alle 8x8 Blöcke im Bild durchlaufen?

image = ... 
block_img = np.zeros(image.shape) 
im_h, im_w = image.shape[:2] 
bl_h, bl_w = 8, 8 

for row in np.arange(im_h - bl_h + 1, step=bl_h): 
    for col in np.arange(im_w - bl_w + 1, step=bl_w): 
     block_img[row:row+bl_h, col:col+bl_w] = apply_histogram(image[row:row+bl_h, col:col+bl_w]) 

image:

Cameraman image

block_img:

Histogram applied to blocks

+0

Danke, das funktioniert perfekt :) – Streem