Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- "cells": [
- {
- "cell_type": "code",
- "execution_count": 5,
- "metadata": {},
- "outputs": [],
- "source": [
- "import cv2\n",
- "import numpy as np"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 2,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "'3.4.5'"
- ]
- },
- "execution_count": 2,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "cv2.__version__"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 6,
- "metadata": {},
- "outputs": [],
- "source": [
- "im=cv2.imread('imagetowork2.jpg')"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 11,
- "metadata": {},
- "outputs": [],
- "source": [
- "blue=im.copy()"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 12,
- "metadata": {},
- "outputs": [],
- "source": [
- "green=im.copy()"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 13,
- "metadata": {},
- "outputs": [],
- "source": [
- "red=im.copy()"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### The original image"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 35,
- "metadata": {},
- "outputs": [],
- "source": [
- "cv2.namedWindow(\"random_image\",cv2.WINDOW_NORMAL)\n",
- "cv2.resizeWindow(\"random_image\",590,332)\n",
- "cv2.imshow(\"random_image\",im)\n",
- "cv2.waitKey(0)\n",
- "cv2.destroyAllWindows()"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### Just to draw blue pic"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 14,
- "metadata": {},
- "outputs": [],
- "source": [
- "blue[:, :, 1] = 0\n",
- "blue[:, :, 2] = 0"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 20,
- "metadata": {},
- "outputs": [],
- "source": [
- "cv2.namedWindow(\"random_image\",cv2.WINDOW_NORMAL)\n",
- "cv2.resizeWindow(\"random_image\",590,332)\n",
- "cv2.imshow(\"random_image\",blue)\n",
- "cv2.waitKey(0)\n",
- "cv2.destroyAllWindows()"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### Just to draw green pic"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 16,
- "metadata": {},
- "outputs": [],
- "source": [
- "green[:, :, 0] = 0\n",
- "green[:, :, 2] = 0"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 17,
- "metadata": {},
- "outputs": [],
- "source": [
- "cv2.namedWindow(\"random_image\",cv2.WINDOW_NORMAL)\n",
- "cv2.resizeWindow(\"random_image\",590,332)\n",
- "cv2.imshow(\"random_image\",green)\n",
- "cv2.waitKey(0)\n",
- "cv2.destroyAllWindows()"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### Just to draw red pic"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 18,
- "metadata": {},
- "outputs": [],
- "source": [
- "red[:, :, 0] = 0\n",
- "red[:, :, 1] = 0"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 19,
- "metadata": {},
- "outputs": [],
- "source": [
- "cv2.namedWindow(\"random_image\",cv2.WINDOW_NORMAL)\n",
- "cv2.resizeWindow(\"random_image\",590,332)\n",
- "cv2.imshow(\"random_image\",red)\n",
- "cv2.waitKey(0)\n",
- "cv2.destroyAllWindows()"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### Just to remove one colour and draw image with two colours(blue and gree)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 25,
- "metadata": {},
- "outputs": [],
- "source": [
- "bg=im.copy()"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 26,
- "metadata": {},
- "outputs": [],
- "source": [
- "bg[:, :, 2] = 0"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 27,
- "metadata": {},
- "outputs": [],
- "source": [
- "cv2.namedWindow(\"random_image\",cv2.WINDOW_NORMAL)\n",
- "cv2.resizeWindow(\"random_image\",590,332)\n",
- "cv2.imshow(\"random_image\",bg)\n",
- "cv2.waitKey(0)\n",
- "cv2.destroyAllWindows()"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### Blue and Red"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 29,
- "metadata": {},
- "outputs": [],
- "source": [
- "br=im.copy()"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 30,
- "metadata": {},
- "outputs": [],
- "source": [
- "br[:, :, 1] = 0"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 31,
- "metadata": {},
- "outputs": [],
- "source": [
- "cv2.namedWindow(\"random_image\",cv2.WINDOW_NORMAL)\n",
- "cv2.resizeWindow(\"random_image\",590,332)\n",
- "cv2.imshow(\"random_image\",br)\n",
- "cv2.waitKey(0)\n",
- "cv2.destroyAllWindows()"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### Green and Red"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 7,
- "metadata": {},
- "outputs": [],
- "source": [
- "gr=im.copy()"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 8,
- "metadata": {},
- "outputs": [],
- "source": [
- "gr[:, :, 0] = 0"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 9,
- "metadata": {},
- "outputs": [],
- "source": [
- "cv2.namedWindow(\"random_image\",cv2.WINDOW_NORMAL)\n",
- "cv2.resizeWindow(\"random_image\",590,332)\n",
- "cv2.imshow(\"random_image\",gr)\n",
- "cv2.waitKey(0)\n",
- "cv2.destroyAllWindows()"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 5,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "array([116, 22, 81], dtype=uint8)"
- ]
- },
- "execution_count": 5,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "im[100][100]"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 21,
- "metadata": {},
- "outputs": [],
- "source": [
- "reddish=im[:,:,0]"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 22,
- "metadata": {},
- "outputs": [
- {
- "data": {
- "text/plain": [
- "(332, 590, 3)"
- ]
- },
- "execution_count": 22,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
- "source": [
- "red.shape"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 24,
- "metadata": {},
- "outputs": [],
- "source": [
- "cv2.imshow('red',reddish)\n",
- "cv2.waitKey(0)\n",
- "cv2.destroyAllWindows()"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 11,
- "metadata": {},
- "outputs": [],
- "source": [
- "bgr=np.random.randint(255, size=(4,4,3), dtype=np.uint8)\n",
- "cv2.namedWindow(\"random_image\",cv2.WINDOW_NORMAL)\n",
- "cv2.resizeWindow(\"random_image\",1000,1000)\n",
- "cv2.imshow(\"random_image\",bgr)\n",
- "cv2.waitKey(0)\n",
- "cv2.destroyAllWindows()"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 12,
- "metadata": {},
- "outputs": [],
- "source": [
- "gr=np.random.randint(0,255, size=(4,4), dtype=np.uint8)\n",
- "cv2.namedWindow(\"random_image\",cv2.WINDOW_NORMAL)\n",
- "cv2.resizeWindow(\"random_image\",1000,1000)\n",
- "cv2.imshow(\"random_image\",gr)\n",
- "cv2.waitKey(0)\n",
- "cv2.destroyAllWindows()"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 5,
- "metadata": {},
- "outputs": [],
- "source": [
- "gray=cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 7,
- "metadata": {},
- "outputs": [],
- "source": [
- "cv2.namedWindow(\"random_image\",cv2.WINDOW_NORMAL)\n",
- "cv2.resizeWindow(\"random_image\",1000,1000)\n",
- "cv2.imshow(\"random_image\",im)\n",
- "cv2.waitKey(0)\n",
- "cv2.destroyAllWindows()"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 8,
- "metadata": {},
- "outputs": [],
- "source": [
- "hsv=cv2.cvtColor(im,cv2.COLOR_BGR2HSV)"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 9,
- "metadata": {},
- "outputs": [],
- "source": [
- "cv2.namedWindow(\"random_image\",cv2.WINDOW_NORMAL)\n",
- "cv2.resizeWindow(\"random_image\",1000,1000)\n",
- "cv2.imshow(\"random_image\",hsv)\n",
- "cv2.waitKey(0)\n",
- "cv2.destroyAllWindows()"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "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.7.1"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 2
- }
Add Comment
Please, Sign In to add comment