NIM : 220605110070

KELAS : A

MATKUL : LINEAR ALGEBRA

DOSEN PENGAMPU : Prof.Dr.Suhartono,M.Kom

JURUSAN : TEKNIK INFORMATIKA

LEMBAGA : UNIVERSITAS ISLAM NEGERI MAULANA MALIK IBRAHIM MALANG

library(magick)
## Warning: package 'magick' was built under R version 4.2.3
## Linking to ImageMagick 6.9.12.3
## Enabled features: cairo, freetype, fftw, ghostscript, heic, lcms, pango, raw, rsvg, webp
## Disabled features: fontconfig, x11

Contoh Contoh Transformasi menggunakan package Magick

  1. Cut and Edit
frink <- image_read("https://jeroen.github.io/images/frink.png")
print(frink)
##   format width height colorspace matte filesize density
## 1    PNG   220    445       sRGB  TRUE    73494   72x72

image_border(image_background(frink, "hotpink"), "#000080", "20x10")

image_trim(frink)

Passport pica

image_crop(frink, "100x150+50")

Resize

image_scale(frink, "300")

Rotate or mirror

image_scale(frink, "x300")

image_rotate(frink, 45)

image_flip(frink)

image_flop(frink)

Brightness, Saturation, Hue

image_modulate(frink, brightness = 80, saturation = 120, hue = 90)

Paint the shirt orange

image_fill(frink, "orange", point = "+100+200", fuzz = 20)

  1. Filters and effects

ImageMagick juga memiliki banyak efek standar yang patut dicoba.

Add randomness

image_blur(frink, 10, 5)

image_noise(frink)

Silly filters

image_charcoal(frink)

image_oilpaint(frink)

image_negate(frink)

  1. Kernel convolution

Konvolusi kernel berarti bahwa setiap nilai piksel dihitung ulang menggunakan jumlah lingkungan berbobot yang ditentukan dalam matriks kernel. Sebagai contoh mari kita lihat kernel sederhana ini:

kern <- matrix(0, ncol = 3, nrow = 3)
kern[1, 2] <- 0.25
kern[2, c(1, 3)] <- 0.25
kern[3, 2] <- 0.25
kern
##      [,1] [,2] [,3]
## [1,] 0.00 0.25 0.00
## [2,] 0.25 0.00 0.25
## [3,] 0.00 0.25 0.00

Kernel ini mengubah setiap piksel menjadi rata-rata piksel tetangga horizontal dan vertikalnya, yang menghasilkan sedikit efek buram pada gambar sebelah kanan di bawah ini:

img <- image_resize(logo, "300x300")
img_blurred <- image_convolve(img, kern)
image_append(c(img, img_blurred))

Atau gunakan salah satu kernel standar

img %>% image_convolve('Sobel') %>% image_negate()

img %>% image_convolve('DoG:0,0,2') %>% image_negate()

  1. Text annotation

berguna untuk mencetak beberapa teks di atas gambar:

add text

image_annotate(frink, "I like R!", size = 70, gravity = "southwest", color = "green")

Customize text

image_annotate(frink, "CONFIDENTIAL", size = 30, color = "red", boxcolor = "pink",
  degrees = 60, location = "+50+100")

Fonts may require ImageMagick has fontconfig

image_annotate(frink, "The quick brown fox", font = 'Times', size = 30)

  1. Combining with pipes Setiap fungsi transformasi gambar mengembalikan salinan yang dimodifikasi dari gambar asli. Itu tidak mempengaruhi gambar asli.
frink <- image_read("https://jeroen.github.io/images/frink.png")
frink2 <- image_scale(frink, "100")
image_info(frink)
##   format width height colorspace matte filesize density
## 1    PNG   220    445       sRGB  TRUE    73494   72x72
image_info(frink2)
##   format width height colorspace matte filesize density
## 1    PNG   100    202       sRGB  TRUE        0   72x72

menggabungkan transformasi

test <- image_rotate(frink, 90)
test <- image_background(test, "blue", flatten = TRUE)
test <- image_border(test, "red", "10x10")
test <- image_annotate(test, "This is how we combine transformations", color = "white", size = 30)
print(test)
##   format width height colorspace matte filesize density
## 1    PNG   465    240       sRGB  TRUE        0   72x72

Menggunakan sintaks pipa magrittr membuatnya sedikit lebih mudah dibaca

image_read("https://jeroen.github.io/images/frink.png") %>%
  image_rotate(270) %>%
  image_background("blue", flatten = TRUE) %>%
  image_border("red", "10x10") %>%
  image_annotate("The same thing with pipes", color = "white", size = 30)