Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
I
image_analyzer
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
John
image_analyzer
Commits
c363831d
Commit
c363831d
authored
Aug 23, 2018
by
John
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implemented image resizing.
parent
c15cc83f
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
115 additions
and
56 deletions
+115
-56
checkit.html
checkit.html
+54
-0
colors.json
colors.json
+6
-0
jcanvas.min.js
jcanvas.min.js
+7
-0
main.rs
src/main.rs
+48
-56
No files found.
checkit.html
0 → 100644
View file @
c363831d
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<meta
charset=
"UTF-8"
>
<title>
Canvas Template
</title>
<style>
body
{
margin
:
0
;
}
</style>
<script
src=
"https://code.jquery.com/jquery-3.3.1.min.js"
integrity=
"sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin=
"anonymous"
></script>
<script
src=
"jcanvas.min.js"
></script>
<script>
var
colors
=
[]
$
.
getJSON
(
"./colors.json"
,
function
(
data
){
console
.
log
(
data
);
for
(
var
i
=
0
;
i
<
data
.
length
;
i
++
)
{
colors
.
push
(
data
[
i
]);
}
});
function
draw
(){
console
.
log
(
"Drawing"
);
// console.log(json);
var
$myCanvas
=
$
(
'#myCanvas'
);
for
(
var
i
=
0
;
i
<
colors
.
length
;
i
++
)
{
$myCanvas
.
drawRect
({
fillStyle
:
"#"
+
colors
[
i
],
strokeStyle
:
'blue'
,
strokeWidth
:
0
,
x
:
(
i
*
100
)
+
200
,
y
:
200
,
fromCenter
:
false
,
width
:
100
,
height
:
100
});
}
}
$
(
"document"
).
ready
(
draw
());
</script>
</head>
<body>
<canvas
id=
"myCanvas"
width=
"1000"
height=
"1000"
>
</canvas>
</body>
</html>
\ No newline at end of file
colors.json
0 → 100644
View file @
c363831d
[
"6b97c1"
,
"a3b5d2"
,
"2c2c3e"
,
"435c7f"
,
"517da7"
]
\ No newline at end of file
jcanvas.min.js
0 → 100644
View file @
c363831d
This diff is collapsed.
Click to expand it.
src/main.rs
View file @
c363831d
extern
crate
image
;
extern
crate
image
;
extern
crate
rusty_machine
;
extern
crate
rusty_machine
;
use
image
::{
FilterType
,
DynamicImage
,
GenericImage
};
use
rusty_machine
::
linalg
::{
Matrix
,
BaseMatrix
};
use
rusty_machine
::
linalg
::{
Matrix
,
BaseMatrix
};
use
rusty_machine
::
learning
::
k_means
::{
KMeansClassifier
};
use
rusty_machine
::
learning
::
k_means
::{
KMeansClassifier
};
use
rusty_machine
::
learning
::
UnSupModel
;
use
rusty_machine
::
learning
::
UnSupModel
;
//extern crate palette;
//extern crate palette;
use
image
::{
GenericImage
,
ImageBuffer
};
fn
get_color
(
px
:
image
::
Rgba
<
u8
>
)
{
//
fn get_color(px:image::Rgba<u8>) {
println!
(
"{:?}"
,
px
);
//
println!("{:?}",px);
//
}
//
}
//
fn
modify
(
val
:
u8
,
percent
:
u32
)
->
u8
{
//
fn modify(val:u8, percent:u32)-> u8{
let
ret
=
((
val
as
u32
*
percent
)
+
50
)
/
100
;
//
let ret=((val as u32*percent)+50)/100;
ret
.min
(
255
)
as
u8
//
ret.min(255) as u8
}
//
}
fn
convert
(
centroids
:
&
Matrix
<
f64
>
){
fn
convert
(
centroids
:
&
Matrix
<
f64
>
){
for
i
in
0
..
centroids
.rows
()
{
println!
(
"{:?}"
,
centroids
.get_row
(
i
)
.unwrap
())
let
mut
colorpalette
=
Vec
::
new
();
for
i
in
0
..
centroids
.rows
()
{
let
colors
=
centroids
.get_row
(
i
)
.unwrap
();
let
hex
=
format!
(
"#{:02x}{:02x}{:02x}"
,
colors
[
0
]
as
u8
,
colors
[
1
]
as
u8
,
colors
[
2
]
as
u8
);
colorpalette
.push
(
hex
);
}
}
println!
(
"{:?}"
,
colorpalette
)
}
}
fn
main
()
{
fn
resize_image
(
img
:
&
DynamicImage
,
maxpix
:
f64
)
->
DynamicImage
{
let
img
=
image
::
open
(
"smalltest.jpg"
)
.unwrap
();
let
dimensions
=
img
.dimensions
();
let
dimensions
=
img
.dimensions
();
let
mut
buff
:
image
::
RgbaImage
=
ImageBuffer
::
new
(
dimensions
.
0
,
dimensions
.
1
);
// Height = Ratio * Width, Area = Width * height, Width = sqrt(Area/Ratio)
// Width = sqrt(A*w0/h0)
let
new_width
=
(
maxpix
*
dimensions
.
0
as
f64
/
dimensions
.
1
as
f64
)
.sqrt
();
let
new_height
=
(
maxpix
*
dimensions
.
1
as
f64
/
dimensions
.
0
as
f64
)
.sqrt
();
let
scaled
=
img
.resize
(
new_width
as
u32
,
new_height
as
u32
,
FilterType
::
Gaussian
);
scaled
}
let
mut
pixelData
=
Vec
::
new
();
fn
main
()
{
let
pixeliter
=
img
.pixels
()
;
let
maxpix
=
100000.0
;
for
pixel
in
pixeliter
{
let
orig_img
=
image
::
open
(
"img.jpg"
)
.unwrap
();
//get_color(pixel.2
);
let
orig_dimensions
=
orig_img
.dimensions
(
);
let
mut
newpix
=
pixel
.clone
()
;
let
mut
img
=
orig_img
;
pixelData
.push
(
newpix
.
2
[
0
]
as
f64
);
pixelData
.push
(
newpix
.
2
[
1
]
as
f64
);
if
orig_dimensions
.
0
*
orig_dimensions
.
1
>
maxpix
as
u32
{
pixelData
.push
(
newpix
.
2
[
2
]
as
f64
);
img
=
resize_image
(
&
img
,
maxpix
);
}
}
println!
(
"{:?}"
,(
dimensions
.
0
*
dimensions
.
1
)
as
usize
);
let
a
=
Matrix
::
new
((
dimensions
.
0
*
dimensions
.
1
)
as
usize
,
3
,
pixelData
);
let
mut
model
=
KMeansClassifier
::
new
(
5
);
let
dimensions
=
img
.dimensions
();
println!
(
"dimensions {:?}"
,
dimensions
);
let
mut
pixel_data
=
Vec
::
new
();
let
pixeliter
=
img
.pixels
();
for
pixel
in
pixeliter
{
pixel_data
.push
(
pixel
.
2
[
0
]
as
f64
);
pixel_data
.push
(
pixel
.
2
[
1
]
as
f64
);
pixel_data
.push
(
pixel
.
2
[
2
]
as
f64
);
}
println!
(
"{:?} Total Pixels"
,(
dimensions
.
0
*
dimensions
.
1
)
as
usize
);
let
a
=
Matrix
::
new
((
dimensions
.
0
*
dimensions
.
1
)
as
usize
,
3
,
pixel_data
);
let
mut
model
=
KMeansClassifier
::
new
(
5
);
model
.train
(
&
a
)
.unwrap
();
model
.train
(
&
a
)
.unwrap
();
println!
(
"{:?}"
,
model
);
println!
(
"{:?}"
,
model
);
let
centroids
=
model
.centroids
()
.as_ref
()
.unwrap
();
let
centroids
=
model
.centroids
()
.as_ref
()
.unwrap
();
println!
(
"Model Centroids:
\n
{:.0}"
,
centroids
);
//
println!("Model Centroids:\n{:.0}", centroids);
convert
(
centroids
);
convert
(
centroids
);
// let slice = MatrixSlice::from_matrix(¢roids, [0,0], 1, 3);
// let slice = MatrixSlice::from_matrix(¢roids, [0,0], 1, 3);
let
slice
=
centroids
.get_row
(
0
)
.unwrap
();
// let slice = centroids.get_row(0).unwrap();
println!
(
"{:?}"
,
slice
);
// let a = model.predict(&test_inputs).unwrap();
// println!("{:?}", e);
// println!("{:?}", m.data());
//
// let pixeliter = img.pixels() ;
// for pixel in pixeliter{
// //get_color(pixel.2);
// let mut newpix = pixel.clone();
// let mut red = newpix.2[0];
// let mut green = newpix.2[1];
// let mut blue = newpix.2[2];
//
// newpix.2[0] = modify(green, 200);
// newpix.2[1]=blue;
// newpix.2[2]=red ;
//
// buff.put_pixel(newpix.0,newpix.1,newpix.2);
// }
// println!("test");
//
//
//
//
buff.save("test.png").unwrap(
);
//
println!("{:?}", slice
);
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment