This tool is written in Python and uses several methods of image manipulation using the pillow library.
First the image is resized based on the width parameter. A magic number of 2.2 is used to account for the difference in height and width of the monospace font.
def resize_image(image, new_width):
image = ImageOps.exif_transpose(image)
width, height = image.size
ratio = height / (2.2 * width)
new_height = int(new_width * ratio)
return image.resize((new_width, new_height))
Next contrast is applied. This is especially important if no edge detection parameter is selected.
def change_contrast(img, level=100):
factor = 259*(level+255)/255*(259-level)
def contrast(c):
return 128 + factor * (c-128)
return img.point(contrast)
Then, color information is removed from the image. We really only need the brightness information for the ASCII representation.
def grayify(image):
return image.convert("L")
And the edges are optionally detected and enhanced.
def detect_edges(image, edge_behavior: str):
behaviors = {
"edge-detect": ImageFilter.FIND_EDGES,
"edge-enhance": ImageFilter.EDGE_ENHANCE,
"edge-none": None
}
behavior = behaviors.get(edge_behavior)
if behavior: return image.filter(behavior)
return image
The pixels are then converted to ASCII characters based on their brightness. The character set is determined by the depth parameter. Each set is ordered based on perceived brightness, and the character set is indexed accordingly.
def pixels_to_ascii(image, depth):
pixels = image.getdata()
ascii_list = [
list(" @"),
list(" /9@"),
list(" ^/([9$@"),
list(" .-^/T(f[j9K$M@"),
list(" `.-':^;!/zTJ(if3[5jwk9OK8$0M%@"),
list(""" `.-':_^=;>!c*/zsTv)J(Fi{fI31t[ne5Yxja]wqkP9d4pOAKXm8D$Bg0MQ%&@""")
]
ASCII_CHARS = ascii_list[depth - 1]
characters = "".join(ASCII_CHARS[p // (256 // len(ASCII_CHARS))] for p in pixels)
return characters
Finally, the above functions are combined and the lines of text are joined on newlines.
def convert_image_from_bytes(image_bytes,
depth,
new_width,
contrast,
edge_behavior):
image = Image.open(BytesIO(image_bytes))
image = resize_image(image, new_width)
image = change_contrast(image, contrast)
image = grayify(image)
image = detect_edges(image, edge_behavior)
ascii_data = pixels_to_ascii(image, depth)
pixel_count = len(ascii_data)
ascii_image = "\n".join(
ascii_data[i:i + new_width]
for i in range(0, pixel_count, new_width)
)
return ascii_image
The full python script can be found here: image_to_ascii.py
Welcome to the BMG CSV Formatter. This tool is used for converting a CSV file into a TXT file format that can be imported into a BMG FluoStar OMEGA plate reader control program. CSV files should be formatted like a 96-well plate. The first column should have the letters A-H, and the top row should have the numbers 1-12. Be sure to input a value for each well you are using even if there are duplicate entries.
def roll_dice(roll, keep):
assert roll >= keep, "roll must be ≥ keep."
rolls = [randint(1,10) for _ in range(roll)]
keeps = sorted(rolls)[::-1][:keep]
for i in keeps:
if i != 10: break
keeps += roll_dice(1, 1)
return keeps
The function first generates a list of length "roll" of random integers between 1 and 10. The rolls are sorted in descending order, and the first "keep" amount of numbers are chosen. If any "keeps" equal 10, the function is called again with roll=1 and keep=1. This goes on until no more 10's are rolled.
Applied Data Scientist specializing in high-throughput biological data and production analytics systems with extensive experience designing end-to-end data workflows, developing custom R packages, and building cloud-backed applications. Skilled in Python, SQL, AWS, and statistical modeling, with a strong foundation in experimental design and high-throughput data. Proven track record of optimizing data analysis pipelines, improving lab efficiency, and delivering actionable insights to drive research and operational success. Jan 2024 – present Aug 2019 – present M.S. in Biotechnology – Texas Tech University 2018 B.S. in Biology – Texas Tech University 2016Gage Rowden
Summary
Skills
Experience
Lead Data Scientist – Priogen Corp.
Researcher IV – University of Minnesota
Education
This is a list of links I’ve found useful or interesting enough to warrant saving here. I never remember to use bookmarks in my browser, so this is the next best thing.Useful Links
Data Science
R
Cheat Sheets
Python
Cheat Sheets
Statistics
Web Development