AAI01, Basic image processing
Back to the previous page |page management|paper review|to NLP
List of posts to read before reading this article
Contents
Building 2d-image with numpy
dtype = np.uint8
import numpy as np
from skimage import io
image = np.array([[255,0,255,0,255,0,255,0,255,0,255,0,255,0,255,0],
[0,255,0,255,0,255,0,255,0,255,0,255,0,255,0,255],
[255,0,255,0,255,0,255,0,255,0,255,0,255,0,255,0],
[0,255,0,255,0,255,0,255,0,255,0,255,0,255,0,255],
[255,0,255,0,255,0,255,0,255,0,255,0,255,0,255,0],
[0,255,0,255,0,255,0,255,0,255,0,255,0,255,0,255],
[255,0,255,0,255,0,255,0,255,0,255,0,255,0,255,0],
[0,255,0,255,0,255,0,255,0,255,0,255,0,255,0,255],
[255,0,255,0,255,0,255,0,255,0,255,0,255,0,255,0],
[0,255,0,255,0,255,0,255,0,255,0,255,0,255,0,255],
[255,0,255,0,255,0,255,0,255,0,255,0,255,0,255,0],
[0,255,0,255,0,255,0,255,0,255,0,255,0,255,0,255]], dtype=np.uint8)
print('dtype : ', image.dtype)
print('shape : ', image.shape)
io.imshow(image)
OUTPUT
dtype : uint8
shape : (12, 16)
<matplotlib.image.AxesImage at 0x260c1d7d630>
dtype = np.int8
import numpy as np
from skimage import io
image = np.array([[255,0,255,0,255,0,255,0,255,0,255,0,255,0,255,0],
[0,255,0,255,0,255,0,255,0,255,0,255,0,255,0,255],
[255,0,255,0,255,0,255,0,255,0,255,0,255,0,255,0],
[0,255,0,255,0,255,0,255,0,255,0,255,0,255,0,255],
[255,0,255,0,255,0,255,0,255,0,255,0,255,0,255,0],
[0,255,0,255,0,255,0,255,0,255,0,255,0,255,0,255],
[255,0,255,0,255,0,255,0,255,0,255,0,255,0,255,0],
[0,255,0,255,0,255,0,255,0,255,0,255,0,255,0,255],
[255,0,255,0,255,0,255,0,255,0,255,0,255,0,255,0],
[0,255,0,255,0,255,0,255,0,255,0,255,0,255,0,255],
[255,0,255,0,255,0,255,0,255,0,255,0,255,0,255,0],
[0,255,0,255,0,255,0,255,0,255,0,255,0,255,0,255]], dtype=np.int8)
print('dtype : ', image.dtype)
print('shape : ', image.shape)
io.imshow(image)
OUTPUT
dtype : int8
shape : (12, 16)
<matplotlib.image.AxesImage at 0x260c1ddf208>
dtype = np.uint16
import numpy as np
from skimage import io
image = np.array([[255,0,255,0,255,0,255,0,255,0,255,0,255,0,255,0],
[0,255,0,255,0,255,0,255,0,255,0,255,0,255,0,255],
[255,0,255,0,255,0,255,0,255,0,255,0,255,0,255,0],
[0,255,0,255,0,255,0,255,0,255,0,255,0,255,0,255],
[255,0,255,0,255,0,255,0,255,0,255,0,255,0,255,0],
[0,255,0,255,0,255,0,255,0,255,0,255,0,255,0,255],
[255,0,255,0,255,0,255,0,255,0,255,0,255,0,255,0],
[0,255,0,255,0,255,0,255,0,255,0,255,0,255,0,255],
[255,0,255,0,255,0,255,0,255,0,255,0,255,0,255,0],
[0,255,0,255,0,255,0,255,0,255,0,255,0,255,0,255],
[255,0,255,0,255,0,255,0,255,0,255,0,255,0,255,0],
[0,255,0,255,0,255,0,255,0,255,0,255,0,255,0,255]], dtype=np.uint16)
print('dtype : ', image.dtype)
print('shape : ', image.shape)
io.imshow(image)
OUTPUT
dtype : uint16
shape : (12, 16)
<matplotlib.image.AxesImage at 0x260c1e96208>
Building 3d-image with numpy
dtype = np.uint8
import numpy as np
from skimage import io
image = np.array([[[255,0,0],[0,255,0],[0,0,255]],
[[0,0,0],[128,128,128],[255,255,255]]], dtype=np.uint8)
print('dtype : ', image.dtype)
print('shape : ', image.shape)
io.imshow(image)
OUTPUT
dtype : uint8
shape : (2, 3, 3)
<matplotlib.image.AxesImage at 0x260c4e91208>
import numpy as np
from skimage import io
image = np.array([[[-1,256,256],[256,-1,256],[256,256,-1]],
[[0,0,0],[-128,-128,-128],[-1,-1,-1]]], dtype=np.uint8)
print('dtype : ', image.dtype)
print('shape : ', image.shape)
io.imshow(image)
OUTPUT
dtype : uint8
shape : (2, 3, 3)
<matplotlib.image.AxesImage at 0x260c516d588>
dtype = np.int8
import numpy as np
from skimage import io
image = np.array([[[255,0,0],[0,255,0],[0,0,255]],
[[0,0,0],[128,128,128],[255,255,255]]], dtype=np.int8)
print('dtype : ', image.dtype)
print('shape : ', image.shape)
io.imshow(image)
OUTPUT
dtype : int8
shape : (2, 3, 3)
<matplotlib.image.AxesImage at 0x260c51ca898>
dtype = np.uint16
import numpy as np
from skimage import io
image = np.array([[[255,0,0],[0,255,0],[0,0,255]],
[[0,0,0],[128,128,128],[255,255,255]]], dtype=np.uint16)
print('dtype : ', image.dtype)
print('shape : ', image.shape)
io.imshow(image)
OUTPUT
dtype : uint16
shape : (2, 3, 3)
<matplotlib.image.AxesImage at 0x260c5282358>
List of posts followed by this article
Reference