[OpenR8 solution] Image_DataAugmentation (Image_DataAugmentation)
  1. Image_DataAugmentation

 

Data Augmentation is achieved by modifying the existing images in the dataset to create more images for the machine to learn, thereby expanding the dataset, enriching the diversity of data, facilitating learning to a wider range of features, and compensating for insufficient data volumes.

 

The goal of this solution is to rotate the image and change the brightness to produce more pictures for the machine to learn. The process file contains: rotate.flow : Rotating (You can set your own several degrees per rotation to produce an image). See Fig. 1 below.

 

rotate_brightness.flow : Rotating + Change brightness. See Fig. 2 below.

 

Fig. 1. rotate.flow. Lena diagram for rotation every 90 degrees..png

Fig. 1. rotate.flow. Lena diagram for rotation every 90 degrees.

 

Fig. 2. rotate_brightness.flow. A schematic diagram of Lena with -30 and.png

Fig. 2. rotate_brightness.flow. A schematic diagram of Lena with +-30 and bright light every 90 degrees.

 

 

  1. Introduction to use

 

This section describes how users can load an existing solution through the R8 software to achieve image data Augmentation.

 

  1. Run R8 and then Load solution.

Step 1. Run R8.exe. Please click on the mouse twice to open R8. See Fig. 3 below.

 

Fig. 3. Run R8.exe ..png

Fig. 3. 【Run R8.exe】.

 

Step 2. Click "File" => "open" above R8. The picture is shown in Fig. 4 below.

 

Fig. 4. File Open ..png

Fig. 4. 【File】=>【Open】.

 

Step 3. Select the Image_dataaugmentation folder under solution. Enter the folder to select the process file to open. The picture is shown in Fig. 5 below.

 

Fig. 5..png

Fig. 5. Select File "Rotate.flow" or "Rotate_brightness.flow".

 

Step 4. After opening the file. The picture is shown in Fig. 6 below.

 

Fig. 6. Run the Rotate.flow up or rotate_brightness.flow down diagram..png

Fig. 6. Run the Rotate.flow (up) or rotate_brightness.flow (down) diagram.

 

  1. Set the input image and the light and dark rotation you want to adjust  【rotate.flow】: rotate

Step 1. Set the rotation angle. Fig. 7 below.

 

Fig. 7. Set the rotation angle..png

Fig. 7. Set the rotation angle.

 

Fig. 8. Set output folder..png

Fig. 8. Set output folder.

 

Step 3. Set the input image. See Fig. 9 below.

 

Fig. 9. Set the input image..png

Fig. 9. Set the input image.

 

【rotate_brightness.flow】 : rotate + bright and dark.

Step 1 ~ 3. Please refer to the Rotate.flow in the same section of this article.

Set the rotation angle + Set output folder + Set the input image. The process is shown in Fig. 10 below.

 

Fig. 10. rotate_brightness. Set rotation angle output folder input image..png

Fig. 10. rotate_brightness. Set rotation angle output folder input image.

 

Step 4. Set the degree of bright and dark. See Fig. 11 below.

 

Fig. 11. rotate_brightness. Set the degree of bright and dark..png

Fig. 11. rotate_brightness. Set the degree of bright and dark.

 

  1. Run and Result.

【rotate.flow】See Fig. 12, Fig. 13 below. 

 

Fig. 12. Run rotate..png

Fig. 12. Run rotate.

 

Fig. 13. The output result of rotate..png

Fig. 13. The output result of rotate.

 

【rotate_brightness.flow】See Fig. 14, Fig. 15 below. 

 

Fig. 14. Run rotate_brightness..png

Fig. 14. Run rotate_brightness.

 

Fig. 15. The output results of rotate_brightness..png

Fig. 15. The output results of rotate_brightness.

 

 

  1. Introduction to the Process - Rotate.flow

 

This section details each block within the process and what role it plays in the solution. The process architecture is shown in Fig. 16 below : 

 

Fig. 16. The flow chart of Rotate.flow..png

Fig. 16. The flow chart of Rotate.flow.

 

The process is from up to bottom :

【1.Println】Set the rotation angle.

Variable name

name

value

Usage

int (Int)

N

4

During execution, the display wants to cut 360 degrees into several pieces.

For example: N = 4, 360/4 = 90 degrees. That is, you want to set the output of a rotation chart every 90 degrees.

bool (Bool)

 

 

 

float (Float)

 

 

 

double (Double)

 

 

 

string (String)

 

 

 

image (Image)

 

 

 

 

【2.Println】Set output folder.

Variable name

name

value

Usage

int (Int)

 

 

 

bool (Bool)

 

 

 

float (Float)

 

 

 

double (Double)

 

 

 

string (String)

outputFolder

rotate_output/

Sets the folder for the image output.

For example, rotate_output/to place the output folder in the Rotate_output folder on the same layer as flow.

image (Image)

 

 

 

 

3 ~ 6】Calculate and display rotation angle.

►3.Int_ToDouble : Converts the set integer N to a floating-point number for the next step to calculate the denominator required to output the image for each degree.

►4.Double_Div : Calculate how much each degree to output an image.

►5.Double_ToInt : Converts the angle calculated from the previous step (with decimals) to an integer.

►6.Println : Displays the degree to which each number of images you want to output.

function

Variable name

name

value

Usage

Int_ToDouble

Int

N

4

The variable you entered.

You want to convert this integer to a float.

Double

N_double

 

Converts an integer to a float to save to this variable.

Double_Div

doubleA

360

360

 

doubleB

N_double

 

 

doubleC

degreeDouble

 

degreeDouble = 360 / N_double

Calculates how much each degree of the image is to be output.

Double_ToInt

Double

 

 

The variable you entered.

You want to convert this float to an integer.

int

degreeInt

 

Save the float as an integer to this variable.

Println

int

degreeInt

 

Displays the angle calculated above.

Bool

 

 

 

float

 

 

 

double

 

 

 

String

 

 

 

image

 

 

 

 
 
【7 Image_Open】Open the image you want to read. The way you select a diagram can be seen in Fig. 17 below.

function

Variable name

value

Usage

imageFileName (String)

imageFileName

lena.png

Read the image of the lena.png.

This variable is called imageFileName.

If you want to change the image of another input. Change the value to the image path name you want to test.

image (Image)

image

 

Save the read-in image to this variable.

 

Fig. 17. Select Output image..png

Fig. 17. Select Output image.

 

【9 ~ 10, 18】Repeat (9 For) to (the end of the For) intermediate process, that is, 10 ~ 17 Repeat operation, until the set conditions are reached.

►9 For

►10 For_GetCounter

►18 For_End

function

Variable name

name

value

Usage

For

counter (Object)

counter

 

The variable that will be used to store the for object.

from (Int)

degreeInt

 

The value at the beginning.

This is the angle at which you want to rotate at the beginning.

For example, when N = 4, it is up to the above steps to know degreeInt = 90 degrees.

to (Int)

to

360

When the angle accumulates above this value, the image of the rotation angle is not continued to be output.

step (Int)

degreeInt

 

How many angles to increase each time.

For_GetCounter

counter (Object)

counter

 

 

count

count

 

Obtain the rotation angle currently to be performed from the counter.

For_End

counter (object)

counter

 

When the set conditions are reached, the process between the "For" and the "For_ end" is no longer running.

This file does not continue when the angle reaches more than 360 degrees.

 
 
【11 ~ 12】Image rotation
►11.Int_ToDouble : Converts the angle (integer) that will be rotated into the floating-point format required for image rotation.
►12.Image_Rotate : Rotate the image.
 

Function

Variable name

name

value

Usage

Int_ToDouble

int

Count

 

The variable you entered. Here is the rotation angle, and you want to convert this int to a float.

double

doubleR

 

The value converted to float is saved to this variable.

Image_Rotate

Image

Image

 

The image you want to rotate.

Degree

doubleR

 

The angle of rotation.

imageRotate

imageRotate

 

Store the rotated image.

 
 
【8, 13 ~ 16】The string that generated the output file name.
►8 String_Replace : lena.png => lena_ (Replace the. png with _)
►13 String_Print : Rotation angle (int) => Rotation angle (string)
►14 String_Add : rotate_output/ + lena_ = rotate_output/lena_
►15 String_Add : rotate_output/lena_ + 30 (The string of angles) = rotate_output/lena_30
►16 String_Add : rotate_output/lena_30 + .png = rotate_output/lena_30.png

Function

Variable name

name

value

Usage

String_Replace

outputString

imageName

 

The processed string is stored in this variable.

replaceFrom

replaceFrom

.png

inputString the words in the text that conform to replaceFrom, replace them with replaceTo.

For example : Enter as Lena.png. After replacing the. png, a new string Lena_ is generated.

replaceTo

replaceTo

_

inputString

imageFileName

lena.png

The file name of the read image. Example is lena.png.

String_Print

outputString

doubleString

 

 

Int

count

 

Displays this int as a string in the DOS window.

This is intended to convert an angle (int) to a string.

bool

 

 

 

float

 

 

 

double

 

 

 

String

 

 

 

image

 

 

 

String_Add

outputString

outputString

 

Output String = string A + string B.

Here is Rotate_output/lena_

string A

outputFolder

rotate_output/

folder where files are stored.

string B

imageName

 

Filename

String_Add

outputString

outputString

 

Output String = string A + string B. For example, String A is 30 (angle). That is, rotate_output/lena_30

string A

outputFolder

 

The merged string above Rotate_output/lena_.

string B

doubleString

 

Angle of rotation (string format)

String_Add

outputString

outputString

 

Output String = string A + string B.

This is Rotate_output/lena_30.png

string A

outputFolder

 

The string merged above

rotate_output/lena_30

string B

stringB

.png

 

 
【17 Image_Save】Stores a rotated image.

Variable name

name

value

Usage

image (Image)

imageRotate

 

The image you want to store.

The imagerotate is the graph

obtained by the image _

rotation above.

imageFileName (String)

outputString

 

The name of the file store.

For example, rotate 30 degrees, this string is Rotate_output/lena_30.png.

 

 

  1. Introduction to the Process - Rotate_brightness.flow

 

This file flowchart is shown in Fig. 18 below: Unlike another process rotate.flow, it is different from adding a bright and dark image to the output.

 

Set "11 Image _ Create" to produce an entire image of 255 pixel and "10_ image create" to produce an entire image of 30 pixels.

 

►Generate Bright Images : Input image increase brightness 30 = input image + 30 = 255 - (255 – input image - 30).  Corresponds to the process is "19 Image_diff" = 255 - 【18 image_diff】= 255 - (【17 image_diff】-30) = 255 - (255 – input image - 30).

►Generate Dark Images : Input image reduces Darkness 30 = input image – 30. Corresponds to the process is "16 image difference" = input image – 30. (This example is a subtraction operation that allows the user to use other means to achieve the same result.) 

 

Fig. 18. The flow chart of Rotate_brightness.flow..png

Fig. 18. The flow chart of Rotate_brightness.flow.


Recommended Article

1.
OpenR8 - AI Software for Everyone (Download)