This file contains hidden or 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
extern crate rand; | |
use std::io; | |
use std::cmp::Ordering; | |
use rand::Rng; | |
fn main() { | |
println!("Guess the number!"); | |
let secret_number = rand::thread_rng().gen_range(1, 101); |
This file contains hidden or 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
def resize_image(img): | |
"""Return a resized image. | |
:param img: | |
""" | |
cropped_image = crop_image(img) | |
if len(cropped_image) >= len(cropped_image[0]): | |
percent = (1.0 - (float(len(cropped_image)) / float(len(img)))) * float(len(img)) | |
else: | |
percent = (1.0 - (float(len(cropped_image[0])) / float(len(img)))) * float(len(img)) |
This file contains hidden or 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
def center_image(img): | |
"""Return a centered image. | |
:param img: | |
""" | |
col_sum = np.where(np.sum(img, axis=0) > 0) | |
row_sum = np.where(np.sum(img, axis=1) > 0) | |
y1, y2 = row_sum[0][0], row_sum[0][-1] | |
x1, x2 = col_sum[0][0], col_sum[0][-1] | |
cropped_image = img[y1:y2, x1:x2] |