{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Bit-slicing\n", "stough 202-\n", "\n", "A quick bit-slicing demo to show that the low-order bits often show little relevant information, while the high-order bits show more. We'll also show this off as an example of [steganography](https://en.wikipedia.org/wiki/Steganography)." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%matplotlib widget\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "import matplotlib.colors as mcolors\n", "import skimage.color as color\n", "from ipywidgets import VBox, HBox, IntSlider\n", "from scipy.interpolate import interp1d\n", "\n", "# For importing from alternative directory sources\n", "import sys \n", "sys.path.insert(0, '../dip_utils')\n", "\n", "from matrix_utils import (arr_info,\n", " make_linmap)\n", "\n", "from vis_utils import (vis_rgb_cube,\n", " vis_hsv_cube,\n", " vis_hists,\n", " vis_pair,\n", " lab_uniform)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "I = plt.imread('../dip_pics/roadforest.jpg')\n", "I = (255*color.rgb2gray(I)).astype('uint8')\n", "\n", "#Load the message image\n", "Im = plt.imread('../dip_pics/happy1BitPad.png')[...,0]\n", "Im = Im.astype('uint8')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "vis_pair(I, Im, show_ticks=False, cmap='gray')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "print(arr_info(I))\n", "print(arr_info(Im))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Use bit-wise and (&0b) to view each plane of the image.\n", "plt.figure(figsize=(6,3))\n", "plt.imshow(I&0x08, cmap='gray');" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Use bit-wise and (&0b) to view each plane of the image.\n", "plt.figure(figsize=(6,3))\n", "plt.imshow(I|Im, cmap='gray');" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "J = I|Im\n", "plt.figure(figsize=(6,3))\n", "plt.imshow(J&0x01, cmap='gray');" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "vis_pair(I, J, cmap='gray')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.10.11" } }, "nbformat": 4, "nbformat_minor": 4 }