Python scipy.ndimage.morphology.dilation

1.7k Views Asked by At

I have a huge problem concerning png images. My png is a black/white letter (The letter is white, the background is black). No colors between them. My problem is, I want/must use in some way binary_dilation/erosion... But when I try to do this, I get an image which is white inside and the background is blue??

from scipy.ndimage.morphology import binary_dilation
from scipy.misc import imread, imsave

template = imread("temp.png")/255.0
imsave("Result.png",binary_dilation(template))

I have absolutely no clue why...

1

There are 1 best solutions below

1
On BEST ANSWER

Beware of the color channels --- if "temp.png" has it, then template.shape == (nx, ny, 3) or with alpha template.shape == (nx, ny, 4). Binary dilation treats the last dimension as the third spatial dimension, rather than as a color channel, which is not what you usually want. You can do binary_dilation(template[:,:,0]) to enforce a 2-D image operation.