-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
105 lines (96 loc) · 2.38 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package main
import (
"fmt"
"matrix-image-manipulation/manipulations"
"matrix-image-manipulation/utils"
"path/filepath"
"strings"
)
func main() {
var path, choice string
// Request the file path from the user
fmt.Print("Qual o path do ficheiro: ")
_, err := fmt.Scanln(&path)
if err != nil {
fmt.Println("Error requesting input from user:", err)
return
}
// Read the image into a matrix
matrix, err := utils.ReadImageToMatrix(path)
if err != nil {
fmt.Println("Error reading image:", err)
return
}
// Ask the user for the operation to perform
fmt.Println("Escolha uma operação:")
fmt.Println("1: Filtro Gaussiano")
fmt.Println("2: Converter para Grayscale")
fmt.Println("3: Alterar Contraste")
fmt.Println("4: Alterar Luminosidade")
fmt.Print("Escolha (1, 2, 3 ou 4): ")
_, err = fmt.Scanln(&choice)
if err != nil {
fmt.Println("Erro a ler a escolha:", err)
return
}
switch choice {
case "1":
matrix, err = manipulations.GaussianFilter(matrix, 7, 10.5)
if err != nil {
fmt.Println("Erro a aplicar filtro Gaussiano:", err)
return
}
case "2":
matrix, err = manipulations.ConvertToGreyScale(matrix)
if err != nil {
fmt.Println("Erro a converter para grayscale:", err)
return
}
case "3":
var m, b float64
fmt.Print("3.1: Insira o valor de m: ")
_, err = fmt.Scanln(&m)
if err != nil {
fmt.Println("Erro a ler o valor de m:", err)
return
}
fmt.Print("3.2: Insira o valor de b: ")
_, err = fmt.Scanln(&b)
if err != nil {
fmt.Println("Erro a ler o valor de b:", err)
return
}
if b == 1 {
b = 255
}
matrix, err = manipulations.AdjustContrast(matrix, m, b)
if err != nil {
fmt.Println("Erro a alterar o contraste:", err)
return
}
case "4":
var b float64
fmt.Print("4.1: Insira o valor de b: ")
_, err = fmt.Scanln(&b)
if err != nil {
fmt.Println("Erro a ler o valor de b:", err)
return
}
matrix, err = manipulations.AdjustLuminosity(matrix, b)
if err != nil {
fmt.Println("Erro a alterar a luminosidade:", err)
return
}
default:
fmt.Println("Escolha inválida.")
return
}
// Write the modified image back to a file
outputPath := strings.TrimSuffix(path, filepath.Ext(path)) + "_new.png"
err = utils.WriteImageFromMatrix(matrix, outputPath)
if err != nil {
fmt.Println("Error writing image:", err)
return
}
fmt.Println("Operação completada. Output guardado em:", outputPath)
}