Image as data
Prerequisites
1. What is Image
On computer vision, image is a set of numeric data. As viusalized, the image is very intuitive, however when we process images, we should approach image as data.
Bascially, Image has features as follows:
(W, H, C)
1
2
3
| width
height
channel
|
pixel
2. How to read image
st_image.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| import cv2 as cv
import os
def getDataPath():
strRoot = os.getcwd()
strDir = os.path.join(strRoot, "data")
return strDir
def getDataPathWithFile(path):
strImage = os.path.join(getDataPath(), path)
return strImage
def readImage(path):
img = cv.imread(path)
return img
def showImage(title, img):
cv.imshow(title, img)
cv.waitKey(0)
cv.destroyAllWindows()
def writeImage(path, img):
cv.imwrite(path, img)
|
main.py
1
2
3
4
5
6
7
8
| import cv2 as cv
import os
import st_image
if __name__ == "__main__":
img = st_image.readImage(st_image.getDataPathWithFile("cat.png"))
st_image.showImage("Cat", img)
st_image.writeImage(st_image.getDataPathWithFile("cat_copy.png"), img)
|