summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordpa <dobaipatakyattila@gmail.com>2026-11-19 16:58:07 +0200
committerdpa <dobaipatakyattila@gmail.com>2026-11-19 16:58:07 +0200
commitc8d109420c38fc47238a984c82eab9da3940f093 (patch)
tree80484cef17e433ab31dc567e10cc0c38a0c6dd68
initial commit
-rw-r--r--README.md20
-rw-r--r--cameraman.pngbin0 -> 112945 bytes
-rw-r--r--conv-flux.jl17
-rw-r--r--conv-opencv.cpp23
-rw-r--r--conv-pytorch.py18
-rw-r--r--conv-scipy.py20
-rw-r--r--conv-test.jl11
7 files changed, 109 insertions, 0 deletions
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..b0b1a45
--- /dev/null
+++ b/README.md
@@ -0,0 +1,20 @@
+# OpenCV vs Flux.jl vs ImageFiltering.jl vs scipy vs pytorch
+
+## Julia (ImageFiltering, Flux)
+- precompile times are long (minutes)
+- i find the syntax much nicer. Example: streaming operator (`.|>`): apply the function `Gray` to each value from `load("./cameraman.png")`
+```julia
+img_gray = load("./cameraman.png") .|> Gray
+```
+- i can interact with the running program (REPL)
+
+## Python (scipy, pytorch)
+- i find the syntax ugly..
+- i can interact with the running program (REPL)
+
+## OpenCV
+- i find it a bit cumbersome, but workable
+- compilation is relatively fast, but i can't interact with the running program
+
+## Neural Network Libs (Flux.jl, Pytorch)
+- they are heavier (might not be needed here, unless we do deep learning)
diff --git a/cameraman.png b/cameraman.png
new file mode 100644
index 0000000..94f2e33
--- /dev/null
+++ b/cameraman.png
Binary files differ
diff --git a/conv-flux.jl b/conv-flux.jl
new file mode 100644
index 0000000..de33910
--- /dev/null
+++ b/conv-flux.jl
@@ -0,0 +1,17 @@
+using Flux, Images, FileIO, ImageView
+
+img_gray = load("./cameraman.png") .|> Gray
+
+img_tensor = Float32.(channelview(img_gray))
+img_tensor = reshape(img_tensor, size(img_tensor)..., 1, 1)
+
+kernel = Float32[1 0 -1; 2 0 -2; 1 0 -1]
+
+weight = reshape(kernel, 3, 3, 1, 1)
+conv_layer = Conv(weight, false)
+
+conv_result = conv_layer(img_tensor)
+
+result_img = colorview(Gray, conv_result[:, :, 1, 1])
+
+imshow(result_img)
diff --git a/conv-opencv.cpp b/conv-opencv.cpp
new file mode 100644
index 0000000..58e32e9
--- /dev/null
+++ b/conv-opencv.cpp
@@ -0,0 +1,23 @@
+#include <iostream>
+#include <opencv2/opencv.hpp>
+
+int main() {
+ cv::Mat img = cv::imread("./cameraman.png", cv::IMREAD_GRAYSCALE);
+ if (img.empty()) {
+ std::cerr << "Failed to load image." << std::endl;
+ return -1;
+ }
+
+ cv::Mat kernel = (cv::Mat_<float>(3, 3) << 1, 0, -1, 2, 0, -2, 1, 0, -1);
+
+ cv::Mat result;
+ cv::filter2D(img, result, CV_32F, kernel, cv::Point(-1, -1), 0,
+ cv::BORDER_REFLECT);
+
+ cv::Mat display;
+ cv::normalize(result, display, 0, 1, cv::NORM_MINMAX);
+ cv::imshow("Sobel X (OpenCV)", display);
+ cv::waitKey(0);
+
+ return 0;
+}
diff --git a/conv-pytorch.py b/conv-pytorch.py
new file mode 100644
index 0000000..b777c53
--- /dev/null
+++ b/conv-pytorch.py
@@ -0,0 +1,18 @@
+import torch
+import torch.nn.functional as F
+import matplotlib.pyplot as plt
+from PIL import Image
+
+img_pil = Image.open("./cameraman.png").convert("L")
+img_tensor = torch.tensor(list(img_pil.getdata()), dtype=torch.float32).reshape(1, 1, img_pil.height, img_pil.width) / 255.0
+
+kernel = torch.tensor([[1., 0., -1.],
+ [2., 0., -2.],
+ [1., 0., -1.]])
+
+weight = kernel.view(1, 1, 3, 3)
+
+conv_result = F.conv2d(img_tensor, weight, padding=1)
+
+plt.imshow(conv_result.squeeze().numpy(), cmap='gray')
+plt.show()
diff --git a/conv-scipy.py b/conv-scipy.py
new file mode 100644
index 0000000..cdc0e87
--- /dev/null
+++ b/conv-scipy.py
@@ -0,0 +1,20 @@
+import numpy as np
+import matplotlib.pyplot as plt
+from scipy import ndimage
+import imageio.v3 as iio
+
+
+img = iio.imread("./cameraman.png")
+print(img.shape, img.dtype)
+
+plt.imshow(img, cmap='gray')
+plt.show()
+
+kernel = np.array([[1, 0, -1],
+ [2, 0, -2],
+ [1, 0, -1]], dtype=np.float64)
+
+conv_result = ndimage.convolve(img.astype(np.float64), kernel, mode='reflect')
+
+plt.imshow(conv_result, cmap='gray')
+plt.show()
diff --git a/conv-test.jl b/conv-test.jl
new file mode 100644
index 0000000..17ba27a
--- /dev/null
+++ b/conv-test.jl
@@ -0,0 +1,11 @@
+using Images, ImageFiltering, FileIO, ImageView
+
+img_gray = load("./cameraman.png") .|> Gray
+
+imshow(img_gray)
+
+kernel = [1 0 -1; 2 0 -2; 1 0 -1]
+
+conv_result = imfilter(img_gray, reflect(centered(kernel)))
+
+imshow(conv_result)