{ "cells": [ { "cell_type": "markdown", "id": "bacterial-vacuum", "metadata": {}, "source": [ "# Simulating Microfilm and Exercises\n", "\n", "Microfilm is a photographic archival format that is very compact for a non-digital format. Each microfiche card will hold about 100 pages of document text and, properly stored, the cards can remain readable for hundreds of years. However, microfilm cameras are designed and adjusted to optimally capture text, using high contrast film and camera settings. This has severe consequences for newspaper photographs and results in a loss of any subtle variations in shade and tone.\n", "\n", "We are simulating the effect of the microfilm process by dramatically increasing the contrast of a given digital photo. This also includes \"cut off\" values for black and white. Any near white pixels within the given white cut off range will be rendered as pure white in the output image. Likewise, any almost black pixels with the black cut off range will be rendered as pure black.\n", "\n", "For the microfilm simulation function we have three settings, the two cut off values and the overall percent by which to enhance contrast." ] }, { "cell_type": "code", "execution_count": 1, "id": "extreme-shore", "metadata": {}, "outputs": [], "source": [ "# This function will return the image transformed as if by microfilm processing.\n", "from PIL import Image, ImageEnhance, ImageOps\n", "def microfilm(image, l_cutoff=17, d_cutoff=10, contrast_lvl=2.9):\n", " im = image.convert(\"L\")\n", " auto = ImageOps.autocontrast(im, cutoff=(l_cutoff, d_cutoff))\n", " enh = ImageEnhance.Contrast(auto)\n", " im = enh.enhance(contrast_lvl) # 2.9 is 290% increase in contrast\n", " return im" ] }, { "cell_type": "markdown", "id": "greenhouse-planner", "metadata": {}, "source": [ "## Exercise: Compare microfilm images to original images\n", "\n", "When you run the code block below, you will see some slider controls and two images. The left image is a digitized photo of Michael Jordan's slam dunk. The right image is a simulated microfilm made from the image on the left. Try adjusting the sliders in order to see how changes in settings effect the microfilm process." ] }, { "cell_type": "code", "execution_count": 2, "id": "executive-harmony", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "f7a1da63367c4a7a8ed72bd6d9ba9d28", "version_major": 2, "version_minor": 0 }, "text/plain": [ "interactive(children=(IntSlider(value=25, description='Light Cutoff:', max=30, min=1), IntSlider(value=25, des…" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from PIL import Image\n", "from ipywidgets import widgets, interact, interactive, fixed, interact_manual\n", "\n", "box_layout = widgets.Layout(display='flex',\n", " flex_flow='row',\n", " align_items='stretch',\n", " border='solid',\n", " width='75%')\n", "\n", "\n", " \n", "def mfw(im, light_cutoff, dark_cutoff, contrast_lvl):\n", " original_out = widgets.Output(layout={'width': '50%', 'border': '1px solid black'})\n", " microfilm_out = widgets.Output(layout={'width': '50%', 'border': '1px solid black'})\n", " with original_out:\n", " print('Input Image')\n", " display(original)\n", " with microfilm_out:\n", " ht = microfilm(im, l_cutoff=light_cutoff, d_cutoff=dark_cutoff, contrast_lvl=contrast_lvl)\n", " print('Simulated Microfilm')\n", " display(ht)\n", " box = widgets.HBox([original_out, microfilm_out], layout=box_layout)\n", " display(box)\n", "\n", "# display widget\n", "original = Image.open('images/Jordan.png')\n", "two = interactive(mfw, im=fixed(original), \n", " dark_cutoff=widgets.IntSlider(description='Dark Cutoff:', min=1, max=30, step=1, value=25), \n", " light_cutoff=widgets.IntSlider(description='Light Cutoff:', min=1, max=30, step=1, value=25),\n", " contrast_lvl=widgets.FloatSlider(description='Contrast Enhancement:', min=1.0, max=4, step=.25, value=3)\n", " )\n", "\n", "display(two)" ] }, { "cell_type": "code", "execution_count": null, "id": "alternative-avenue", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.6" } }, "nbformat": 4, "nbformat_minor": 5 }