You are on page 1of 5

In [2]:

import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

In [3]:
import cv2

In [4]:

img = cv2.imread('D:/1234.jpg')

In [5]:

type(img)
Out[5]:

numpy.ndarray

In [6]:
plt.imshow(img)

Out[6]:
<matplotlib.image.AxesImage at 0x2343d4186d8>

In [7]:
img.shape

Out[7]:
(1148, 999, 3)

In [8]:
orig_img = cv2.cvtColor(img,cv2.COLOR_BGR2RGB)

In [9]:
plt.imshow(orig_img)
Out[9]:

<matplotlib.image.AxesImage at 0x2343d4ab978>
In [10]:
gray_img = cv2.imread('D:/1234.jpg',cv2.IMREAD_GRAYSCALE)

In [11]:
plt.imshow(gray_img)
Out[11]:
<matplotlib.image.AxesImage at 0x2343d506dd8>

In [12]:
plt.imshow(gray_img,cmap='gray')
Out[12]:
<matplotlib.image.AxesImage at 0x2343d6fcbe0>

In [13]:
new_img = cv2.resize(orig_img,(600,400))

In [14]:
plt.imshow(new_img)
Out[14]:
<matplotlib.image.AxesImage at 0x2343e7377b8>

In [15]:
w = 0.5
h = 0.2

In [16]:

new_img1 = cv2.resize(orig_img,(0,0),orig_img,w,h)

In [17]:
plt.imshow(new_img1)
Out[17]:
<matplotlib.image.AxesImage at 0x2343e79a4a8>

In [18]:
new_img2 = cv2.flip(orig_img,0)
plt.imshow(new_img2)
Out[18]:
<matplotlib.image.AxesImage at 0x2343e7eacf8>
In [19]:
new_img2 = cv2.flip(orig_img,1)
plt.imshow(new_img2)
Out[19]:
<matplotlib.image.AxesImage at 0x2343e840908>

In [20]:
new_img2 = cv2.flip(orig_img,-1)
plt.imshow(new_img2)
Out[20]:
<matplotlib.image.AxesImage at 0x2343e8985c0>

In [21]:
cv2.imwrite('D:/123.jpg',new_img2)
Out[21]:
True

In [22]:
fig = plt.figure(figsize=(10,10))
ax = fig.add_subplot(111)
ax.imshow(img)
Out[22]:
<matplotlib.image.AxesImage at 0x2343e8f0438>
In [ ]:

You might also like