GS321 - 3 - Image Preprocessing in R
GS321 - 3 - Image Preprocessing in R
Instructor:
Dr. Msusa
Mr. Wangabo
Introduction
A few problems associated with image data include complexity, inaccuracy,
and inadequacy. This is why before building a computer vision model, it is
essential that the data is preprocessed (cleaned and processed to the desired
format) to achieve the desired results.
Prerequisites
To follow through the tutorial, one needs:
• RStudio
• Kaggle R
4. Combine
5. Manipulating Contrast
6. Gamma Correction
7. Colour Change
8. Cropping
9. Saving
library(EBImage)
library(jpeg)
# Check data
display(image_1)
print(image_1)
# check data
display(image_2)
print(image_2)
When we compare the first table of image_1 and the last one, we see the
numbers are different. The first table arrays are around 0 and the last one
around -0.4
Image
colorMode : Color
storage.mode : double
dim : 4250 5500 3
frames.total : 3
frames.render: 1
imageData(object)[1:5,1:6,1]
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 0.6 0.6 0.6 0.6 0.6 0.6
[2,] -0.4 -0.4 -0.4 -0.4 -0.4 -0.4
[3,] -0.4 -0.4 -0.4 -0.4 -0.4 -0.4
[4,] -0.4 -0.4 -0.4 -0.4 -0.4 -0.4
[5,] -0.4 -0.4 -0.4 -0.4 -0.4 -0.4
As we can see the new image is brighter than the original one.
display(brightened_image)
imageData(object)[1:5,1:6,1]
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 1 1 1 1 1 1
[2,] 0 0 0 0 0 0
[3,] 0 0 0 0 0 0
[4,] 0 0 0 0 0 0
[5,] 0 0 0 0 0 0
To display all frames use 'all = TRUE'.
8. Cropping
# cropping
cropped_image <- image_1[3102:2023, 2014:1252, ] # we just select x, y axis, z is blank
display(cropped_image)
9. Saving
# let's save the crop file cropped_image
# new image file
writeImage(cropped_image, "E:/land/NewImage.jpg")
Good luck!
Image Processing