In order to improve the accuracy of classification such as CNN of deep learning, a good training data set is required. In order to ensure accuracy, it is necessary to devise the following.
To do these, you just need a number of sheets. Depending on the type, the number of sheets may be biased, and it is difficult to extract and tag all by hand.
Therefore, we will consider increasing the number of images by processing the images that have been tagged to some extent. Here are some of the techniques. In the explanation, based on the opinion that Reni Takagi should be used as a sample for image processing, Reni Takagi To use.
Implemented in OpenCV 3.0 Python. Here is a sauce that you can actually use for padding.
Creates an image with enhanced and reduced contrast. To emphasize, set 0 for low-brightness pixels below a certain level and 255 for high-brightness pixels above a certain level, and adjust those with intermediate brightness. Conversely, to reduce it, adjust the brightness width to a smaller value. This figure is easy to understand.
#Look-up table generation
min_table = 50
max_table = 205
diff_table = max_table - min_table
LUT_HC = np.arange(256, dtype = 'uint8' )
LUT_LC = np.arange(256, dtype = 'uint8' )
#High contrast LUT creation
for i in range(0, min_table):
LUT_HC[i] = 0
for i in range(min_table, max_table):
LUT_HC[i] = 255 * (i - min_table) / diff_table
for i in range(max_table, 255):
LUT_HC[i] = 255
#Create low contrast LUT
for i in range(256):
LUT_LC[i] = min_table + i * (diff_table) / 255
#conversion
src = cv2.imread("reni.jpg ", 1)
high_cont_img = cv2.LUT(src, LUT_HC)
low_cont_img = cv2.LUT(src, LUT_LC)
Contrast emphasized
Reduced contrast
reference Image density conversion with tone curve
This conversion is used when displaying on a display, and changes the brightness value according to the value of γ.
Replace the contrast adjustment source lookup table here.
#Gamma conversion lookup table
gamma1 = 0.75
gamma2 = 1.5
for i in range(256):
LUT_G1[i] = 255 * pow(float(i) / 255, 1.0 / gamma1)
LUT_G2[i] = 255 * pow(float(i) / 255, 1.0 / gamma2)
When γ = 1.5
When γ = 0.75
reference Lookup table (example of gamma correction)
Smooths the image. Here, the averaging filter is applied.
average_square = (10,10)
src = cv2.imread("reni.jpg ", 1)
blur_img = cv2.blur(src, average_square)
10x10 averaging filter
reference Smoothing (moving average, Gaussian) filter
Add noise to each pixel by adding the generated value based on the Gaussian distribution.
Gaussian noise with σ = 15
src = cv2.imread("reni.jpg ", 1)
row,col,ch= src.shape
mean = 0
sigma = 15
gauss = np.random.normal(mean,sigma,(row,col,ch))
gauss = gauss.reshape(row,col,ch)
gauss_img = src + gauss
reference Conversion of image information (brightness data)
It's called this because it's a noise like salt and pepper. It is also called impulse noise.
src = cv2.imread("reni.jpg ", 1)
row,col,ch = src.shape
s_vs_p = 0.5
amount = 0.004
sp_img = src.copy()
#Salt mode
num_salt = np.ceil(amount * src.size * s_vs_p)
coords = [np.random.randint(0, i-1 , int(num_salt)) for i in src.shape]
sp_img[coords[:-1]] = (255,255,255)
#Pepper mode
num_pepper = np.ceil(amount* src.size * (1. - s_vs_p))
coords = [np.random.randint(0, i-1 , int(num_pepper)) for i in src.shape]
sp_img[coords[:-1]] = (0,0,0)
Noise on 0.4% pixels
Flip left and right and flip up and down.
src = cv2.imread("reni.jpg ", 1)
hflip_img = cv2.flip(src, 1)
vflip_img = cv2.flip(src, 0)
Enlarges or reduces part of the image.
src = cv2.imread("reni.jpg ", 1)
hight = src.shape[0]
width = src.shape[1]
half_img = cv2.resize(src,(hight/2,width/2))
Recommended Posts