I'm starting to play with openCV & am working through the Programming Computer Vision with Python book. It seems like I have a default that's set as the inverse (or reverse?) of what the book is using because where the image is black on my computer, the image is white in the book.
Is there any way to set the default to flip the white & black without doing a calculation each time?
Here's some sample code from the book. In the book, the background is white, but on my computer, it is black:
from PIL import Image
from numpy import *
from scipy.ndimage import filters
im = array(Image.open('empire.jpg').convert('L'))
sigma = 5
imx = zeros(im.shape)
filters.gaussian_filter(im,(sigma,sigma),(0,1),imx)
imy = zeros(im.shape)
filters.gaussian_filter(im,(sigma,sigma),(1,0),imy)
magnitude = sqrt(imx**2+imy**2)
figure()
subplot(1,4,1)
imshow(im)
subplot(1,4,2)
imshow(imx)
subplot(1,4,3)
imshow(imy)
subplot(1,4,4)
imshow(magnitude)
I'm on a mac book pro & using python 2.7. This has probably been answered somewhere, but I couldn't find an answer - probably not using the right tags/keywords... thx in advance.
It's not default, but you can invert the colors by subtract the array from 1:
plt.imshow(1 - array)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With