{ "cells": [ { "cell_type": "code", "execution_count": 1, "id": "76c11d1b", "metadata": {}, "outputs": [], "source": [ "import cv2 as cv\n", "import numpy as np" ] }, { "cell_type": "code", "execution_count": 2, "id": "9b23b408", "metadata": {}, "outputs": [], "source": [ "img = cv.imread('reflections.jpg')" ] }, { "cell_type": "code", "execution_count": 3, "id": "33367d3a", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "numpy.ndarray" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "type(img)" ] }, { "cell_type": "code", "execution_count": 15, "id": "49569358", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(320, 900, 3)" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "img.shape" ] }, { "cell_type": "code", "execution_count": 5, "id": "6f0df354", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "864000" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "img.size" ] }, { "cell_type": "code", "execution_count": 6, "id": "f527fc78", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "864000" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "320*900*3" ] }, { "cell_type": "code", "execution_count": 7, "id": "ec217e25", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "dtype('uint8')" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "img.dtype" ] }, { "cell_type": "code", "execution_count": 8, "id": "df757a4d", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([24, 70, 64], dtype=uint8)" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "img[100,100]" ] }, { "cell_type": "code", "execution_count": 9, "id": "19809eec", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "24" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "img[100,100,0]" ] }, { "cell_type": "code", "execution_count": 10, "id": "30f6d188", "metadata": {}, "outputs": [], "source": [ "cv.imshow('image', img)\n", "cv.waitKey(0)\n", "cv.destroyAllWindows()" ] }, { "cell_type": "code", "execution_count": 11, "id": "459bd7f3", "metadata": {}, "outputs": [], "source": [ "for r in range(100):\n", " for c in range(100):\n", " img[r,c] = np.array([5,50,180])" ] }, { "cell_type": "code", "execution_count": 12, "id": "f148d62e", "metadata": {}, "outputs": [], "source": [ "cv.imshow('altered image', img)\n", "cv.waitKey(0)\n", "cv.destroyAllWindows()" ] }, { "cell_type": "code", "execution_count": 13, "id": "60ebf979", "metadata": {}, "outputs": [], "source": [ "img[100:200,100:200] = np.array([5,50,180])" ] }, { "cell_type": "code", "execution_count": 14, "id": "f3ea20de", "metadata": {}, "outputs": [], "source": [ "cv.imshow('altered image', img)\n", "cv.waitKey(0)\n", "cv.destroyAllWindows()" ] }, { "cell_type": "code", "execution_count": 16, "id": "5c316cae", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "320" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "img.shape[0]" ] }, { "cell_type": "code", "execution_count": 17, "id": "2de6933d", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "900" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "img.shape[1]" ] }, { "cell_type": "code", "execution_count": 18, "id": "b7b8b2ea", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "img.shape[2]" ] }, { "cell_type": "code", "execution_count": 19, "id": "720c681d", "metadata": {}, "outputs": [], "source": [ "img[200:300,200:300,2] = 128 " ] }, { "cell_type": "code", "execution_count": 20, "id": "77cbc415", "metadata": {}, "outputs": [], "source": [ "cv.imshow('altered image', img)\n", "cv.waitKey(0)\n", "cv.destroyAllWindows()" ] }, { "cell_type": "code", "execution_count": 21, "id": "769f68bf", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "True" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cv.imwrite('alteredreflections.jpg', img)" ] }, { "cell_type": "code", "execution_count": 22, "id": "8b5ffdd5", "metadata": {}, "outputs": [], "source": [ "squarechunk = img[200:300, 600:700]" ] }, { "cell_type": "code", "execution_count": 23, "id": "5f53fb9b", "metadata": {}, "outputs": [], "source": [ "cv.imshow('altered image', squarechunk)\n", "cv.waitKey(0)\n", "cv.destroyAllWindows()" ] }, { "cell_type": "code", "execution_count": null, "id": "d15d3094", "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.12.3" } }, "nbformat": 4, "nbformat_minor": 5 }