Skip to content

Commit

Permalink
Finalizing
Browse files Browse the repository at this point in the history
  • Loading branch information
awxkee committed Sep 25, 2024
1 parent 841ab4e commit d79df94
Show file tree
Hide file tree
Showing 25 changed files with 1,774 additions and 269 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
/converted_rgb.png
.idea
target
app/target
app/target
dilated.jpg
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@ exclude = ["*.jpg", "*.png"]
[dependencies]
colorutils-rs = "0.5.12"
num-traits = "0.2.19"
rayon = "1.10.0"
rayon = "1.10.0"
image = { version = "0.25.0", optional = true, default-features = false }

[features]
default = []
image = ["dep:image"]
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,25 @@ dilate_rgb(
).unwrap();
```

#### Usage with image crate

```rust
let img = ImageReader::open("./assets/fruits.jpg")
.unwrap()
.decode()
.unwrap();
let new_image = morphology_image(
img,
MorphOp::Dilate,
&structuring_element,
KernelShape::new(se_size, se_size),
BorderMode::default(),
MorphologyThreadingPolicy::default(),
)
.unwrap();
new_image.save("dilated.jpg").unwrap();
```

## Results

Here is some examply bokeh effect
Expand All @@ -24,6 +43,13 @@ Here is some examply bokeh effect
<img src="https://github.com/awxkee/fast_morphology/blob/master/assets/bokeh.jpg?raw=true" width="273" height="409">
</p>

And erosion

<p float="left">
<img src="https://github.com/awxkee/fast_morphology/blob/master/assets/fruits.jpg?raw=true" width="273" height="409">
<img src="https://github.com/awxkee/fast_morphology/blob/master/assets/erosion.jpg?raw=true" width="273" height="409">
</p>

# Benchmarking

If you wish to run benchmarks then
Expand Down
4 changes: 2 additions & 2 deletions app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ edition = "2021"

[dependencies]
image = "0.25.2"
fast_morphology = {path = "../"}
fast_morphology = {path = "../", features = ["image"]}
imageproc = "0.25.0"
opencv = {version = "0.93.0", features = ["imgproc"]}
opencv = {version = "0.93.0", features = ["imgproc", "clang-runtime"]}

[dev-dependencies]
criterion = {version = "0.5.1", features = ["html_reports"]}
Expand Down
22 changes: 11 additions & 11 deletions app/benches/dilation/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,18 +321,18 @@ pub fn criterion_benchmark(c: &mut Criterion) {
exec_bench_rgb(c, 10);
exec_bench_rgb(c, 20);
exec_bench_rgb(c, 30);
//
// exec_bench_rgba(c, 4);
// exec_bench_rgba(c, 7);
// exec_bench_rgba(c, 10);
// exec_bench_rgba(c, 20);
// exec_bench_rgba(c, 30);

// exec_bench_gray(c, 4);
// exec_bench_gray(c, 7);
// exec_bench_gray(c, 10);
// exec_bench_gray(c, 20);
// exec_bench_gray(c, 30);
exec_bench_rgba(c, 4);
exec_bench_rgba(c, 7);
exec_bench_rgba(c, 10);
exec_bench_rgba(c, 20);
exec_bench_rgba(c, 30);

exec_bench_gray(c, 4);
exec_bench_gray(c, 7);
exec_bench_gray(c, 10);
exec_bench_gray(c, 20);
exec_bench_gray(c, 30);
}

criterion_group!(benches, criterion_benchmark);
Expand Down
27 changes: 20 additions & 7 deletions app/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use fast_morphology::{
dilate, dilate_rgb, dilate_rgba, BorderMode, ImageSize, KernelShape, MorphologyThreadingPolicy,
dilate, dilate_rgb, dilate_rgba, erode, erode_rgba, morphology_image, BorderMode, ImageSize,
KernelShape, MorphExOp, MorphologyThreadingPolicy,
};
use image::{EncodableLayout, GenericImageView, ImageReader};
use opencv::core::{
Expand Down Expand Up @@ -65,7 +66,7 @@ fn gaussian_kernel(size: usize, sigma: f32) -> Vec<Vec<f32>> {
}

fn main() {
let radius_size = 55;
let radius_size = 10;
let mut structuring_element = circle_se(radius_size);

opencv::core::set_use_opencl(false).expect("Failed to disable OpenCL");
Expand Down Expand Up @@ -114,7 +115,7 @@ fn main() {

let image_size = ImageSize::new(dimensions.0 as usize, dimensions.1 as usize);

dilate(
erode(
&channel_1_src,
&mut channel_1_dst,
image_size,
Expand All @@ -125,7 +126,7 @@ fn main() {
)
.unwrap();

dilate(
erode(
&channel_2_src,
&mut channel_2_dst,
image_size,
Expand All @@ -136,7 +137,7 @@ fn main() {
)
.unwrap();

dilate(
erode(
&channel_3_src,
&mut channel_3_dst,
image_size,
Expand Down Expand Up @@ -166,7 +167,7 @@ fn main() {
let mut dst = vec![0u8; rgba_image.len()];

let exec_time = Instant::now();
dilate_rgba(
erode_rgba(
&rgba_image,
&mut dst,
image_size,
Expand Down Expand Up @@ -207,7 +208,7 @@ fn main() {
let exec_time = Instant::now();

let mut dst_mat = Mat::default();
imgproc::dilate(
imgproc::erode(
&mat,
&mut dst_mat,
&kernel,
Expand All @@ -222,6 +223,18 @@ fn main() {

println!("opencv exec time {:?}", exec_time.elapsed());

let new_image = morphology_image(
img,
MorphExOp::Erode,
&structuring_element,
KernelShape::new(se_size, se_size),
BorderMode::default(),
MorphologyThreadingPolicy::default(),
)
.unwrap();

new_image.save("dilated.jpg").unwrap();

image::save_buffer(
"converted.png",
&bytes,
Expand Down
Binary file added assets/erosion.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit d79df94

Please sign in to comment.