-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
1,044 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# traceskeleton.rs | ||
|
||
Rust version. | ||
|
||
|
||
## Usage | ||
|
||
```rust | ||
mod trace_skeleton; pub use trace_skeleton::*; | ||
|
||
let mut im : Vec<u8> = vec![0,1,0,1,0,...]; // image | ||
let w = 100; // width | ||
let h = 100; // height | ||
|
||
//raster thinning | ||
trace_skeleton::thinnning_zs(&mut im, w, h); | ||
|
||
//trace skeleton to polylines | ||
let p : Vec<Vec<[usize;2]>> = trace_skeleton::trace_skeleton(&mut im,w,h,0,0,w,h,10,999); | ||
|
||
//render as svg string | ||
let svg : String = trace_skeleton::polylines_to_svg(&p,w,h); | ||
|
||
``` | ||
|
||
|
||
## Compile | ||
|
||
First compile | ||
|
||
``` | ||
rustc -O example.rs | ||
``` | ||
|
||
Then run | ||
|
||
``` | ||
./example img.txt | ||
``` | ||
|
||
Output will be written to `out.svg` | ||
|
||
- `-O` should be passed to the compiler to gain a ~100x speedup. | ||
- `img.txt` is an text file filled with "0" and "1" representing a bitmap image. | ||
|
||
|
||
**Developed at [Frank-Ratchye STUDIO for Creative Inquiry](https://studioforcreativeinquiry.org) at Carnegie Mellon University.** |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
mod trace_skeleton; pub use trace_skeleton::*; | ||
|
||
fn read_txt_as_image(path:String) -> (Vec<u8>,usize,usize){ | ||
let txt = std::fs::read_to_string(path).expect("Unable to read file"); | ||
let bts = txt.as_bytes(); | ||
let mut im : Vec<u8> = vec![]; | ||
let mut w : usize = 0; | ||
let mut h : usize = 1; | ||
for i in 0..bts.len(){ | ||
if bts[i] == 48{ | ||
im.push(0); | ||
w+=1; | ||
}else if bts[i] == 49{ | ||
im.push(1); | ||
w+=1; | ||
}else if bts[i] == 10{ | ||
h+=1; | ||
w=0; | ||
} | ||
} | ||
return (im,w,h); | ||
} | ||
|
||
fn main(){ | ||
let argv: Vec<_> = std::env::args().collect(); | ||
let (mut im,w,h) = read_txt_as_image(argv[1].clone()); | ||
|
||
trace_skeleton::thinning_zs(&mut im,w,h); | ||
|
||
// for i in 0..h{for j in 0..w{print!("{}",im[i*w+j]);}println!();} | ||
|
||
let now = std::time::Instant::now(); | ||
let p : Vec<Vec<[usize;2]>> = trace_skeleton::trace_skeleton(&mut im,w,h,0,0,w,h,10,999); | ||
let elapsed = now.elapsed(); | ||
println!("Elapsed: {:.2?}", elapsed); | ||
|
||
let svg : String = trace_skeleton::polylines_to_svg(&p,w,h); | ||
|
||
std::fs::write("out.svg", svg).expect("Unable to write file"); | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.