In [18]:
photo_data = misc.imread('./wifire/sd-3layers.jpg')
/home/hyeok/anaconda3/lib/python3.7/site-packages/ipykernel_launcher.py:1: DeprecationWarning: `imread` is deprecated!
`imread` is deprecated in SciPy 1.0.0, and will be removed in 1.2.0.
Use ``imageio.imread`` instead.
  """Entry point for launching an IPython kernel.
In [19]:
photo_data.shape
Out[19]:
(3725, 4797, 3)
In [23]:
low_value_filter = photo_data < 100
low_value_filter.shape
Out[23]:
(3725, 4797, 3)
In [24]:
low_value_filter[ : 10 , : 10 , 0]
Out[24]:
array([[ True,  True,  True,  True,  True,  True,  True,  True,  True,
         True],
       [ True,  True,  True,  True,  True,  True,  True,  True,  True,
         True],
       [ True,  True,  True,  True,  True,  True,  True,  True,  True,
         True],
       [ True,  True,  True,  True,  True,  True,  True,  True,  True,
         True],
       [ True,  True,  True,  True,  True,  True,  True,  True,  True,
         True],
       [ True,  True,  True,  True,  True,  True,  True,  True,  True,
         True],
       [ True,  True,  True,  True,  True,  True,  True,  True,  True,
         True],
       [ True,  True,  True,  True,  True,  True,  True,  True,  True,
         True],
       [ True,  True,  True,  True,  True,  True,  True,  True,  True,
         True],
       [ True,  True,  True,  True,  True,  True,  True,  True,  True,
         True]])
In [25]:
import random
plt.figure(figsize=(10, 10))
plt.imshow(photo_data)
photo_data[low_value_filter] = 0
plt.figure(figsize = (10, 10))
plt.imshow(photo_data)
Out[25]:
<matplotlib.image.AxesImage at 0x7f1641221eb8>
In [27]:
rows_range = np.arange(len(photo_data))
cols_range = rows_range
type(rows_range)
Out[27]:
numpy.ndarray
In [31]:
rows_range.shape, cols_range.shape
Out[31]:
((3725,), (3725,))
In [32]:
photo_data[rows_range, cols_range] = 255
In [33]:
plt.figure(figsize=(15,15))
plt.imshow(photo_data)
Out[33]:
<matplotlib.image.AxesImage at 0x7f1641192630>
In [35]:
total_rows , total_cols, totoal_layers = photo_data.shape
x , y = np.ogrid[ : total_rows,  : total_cols]


x.shape, y.shape, photo_data.shape
Out[35]:
((3725, 1), (1, 4797), (3725, 4797, 3))
In [48]:
center_row, center_col = total_rows / 2 , total_cols / 2
#center_row, center_col
#x - center_row
#y - center_col

dist_from_center = (x - center_row)**2 + (y - center_col)**2
#dist_from_center.shape

radius = (total_rows/ 2)**2
circular_mask = (dist_from_center > radius)

circular_mask[1500:1700, 2000:3000]
Out[48]:
array([[False, False, False, ..., False, False, False],
       [False, False, False, ..., False, False, False],
       [False, False, False, ..., False, False, False],
       ...,
       [False, False, False, ..., False, False, False],
       [False, False, False, ..., False, False, False],
       [False, False, False, ..., False, False, False]])
In [49]:
photo_data = misc.imread('./wifire/sd-3layers.jpg')
photo_data[circular_mask] = 0
plt.figure(figsize=(15,15))
plt.imshow(photo_data)
/home/hyeok/anaconda3/lib/python3.7/site-packages/ipykernel_launcher.py:1: DeprecationWarning: `imread` is deprecated!
`imread` is deprecated in SciPy 1.0.0, and will be removed in 1.2.0.
Use ``imageio.imread`` instead.
  """Entry point for launching an IPython kernel.
Out[49]:
<matplotlib.image.AxesImage at 0x7f16411005f8>
In [51]:
x, y = np.ogrid[ : total_rows, : total_cols]
half_upper = x < center_row

half_upper_mask = np.logical_and(half_upper, circular_mask)
In [53]:
photo_data = misc.imread('./wifire/sd-3layers.jpg')
photo_data[half_upper_mask] = 255
plt.figure(figsize=(15,15))
plt.imshow(photo_data)
/home/hyeok/anaconda3/lib/python3.7/site-packages/ipykernel_launcher.py:1: DeprecationWarning: `imread` is deprecated!
`imread` is deprecated in SciPy 1.0.0, and will be removed in 1.2.0.
Use ``imageio.imread`` instead.
  """Entry point for launching an IPython kernel.
Out[53]:
<matplotlib.image.AxesImage at 0x7f1640f0cbe0>

In [54]:
half_upper.shape
Out[54]:
(3725, 1)
In [55]:
half_upper_mask.shape
Out[55]:
(3725, 4797)
In [56]:
photo_data = misc.imread('./wifire/sd-3layers.jpg')
red_mask = photo_data[: , : , 0 ] < 150
photo_data[red_mask] = 0
plt.figure(figsize=(15,15))
plt.imshow(photo_data)
/home/hyeok/anaconda3/lib/python3.7/site-packages/ipykernel_launcher.py:1: DeprecationWarning: `imread` is deprecated!
`imread` is deprecated in SciPy 1.0.0, and will be removed in 1.2.0.
Use ``imageio.imread`` instead.
  """Entry point for launching an IPython kernel.
Out[56]:
<matplotlib.image.AxesImage at 0x7f164092be10>

In [57]:
photo_data = misc.imread('./wifire/sd-3layers.jpg')
red_mask = photo_data[: , : , 0 ] < 150
green_mask = photo_data[: , : , 1 ] > 100
blue_mask = photo_data[: , : , 2 ] < 100

final_mask = np.logical_and(red_mask, green_mask, blue_mask)

photo_data[final_mask] = 0
plt.figure(figsize=(15,15))
plt.imshow(photo_data)
/home/hyeok/anaconda3/lib/python3.7/site-packages/ipykernel_launcher.py:1: DeprecationWarning: `imread` is deprecated!
`imread` is deprecated in SciPy 1.0.0, and will be removed in 1.2.0.
Use ``imageio.imread`` instead.
  """Entry point for launching an IPython kernel.
Out[57]:
<matplotlib.image.AxesImage at 0x7f1640bc5f28>


'Python Library > Numpy' 카테고리의 다른 글

Day 4. Image Processing with a numpy - 01  (0) 2019.06.12
Day 4. Numpy02  (0) 2019.06.12
Day 3. Numpy01  (0) 2019.06.11

+ Recent posts