daily pastebin goal
19%
SHARE
TWEET

Untitled

a guest Jan 22nd, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {
  2.  "cells": [
  3.   {
  4.    "cell_type": "code",
  5.    "execution_count": 5,
  6.    "metadata": {},
  7.    "outputs": [],
  8.    "source": [
  9.     "import cv2\n",
  10.     "import numpy as np"
  11.    ]
  12.   },
  13.   {
  14.    "cell_type": "code",
  15.    "execution_count": 2,
  16.    "metadata": {},
  17.    "outputs": [
  18.     {
  19.      "data": {
  20.       "text/plain": [
  21.        "'3.4.5'"
  22.       ]
  23.      },
  24.      "execution_count": 2,
  25.      "metadata": {},
  26.      "output_type": "execute_result"
  27.     }
  28.    ],
  29.    "source": [
  30.     "cv2.__version__"
  31.    ]
  32.   },
  33.   {
  34.    "cell_type": "code",
  35.    "execution_count": 6,
  36.    "metadata": {},
  37.    "outputs": [],
  38.    "source": [
  39.     "im=cv2.imread('imagetowork2.jpg')"
  40.    ]
  41.   },
  42.   {
  43.    "cell_type": "code",
  44.    "execution_count": 11,
  45.    "metadata": {},
  46.    "outputs": [],
  47.    "source": [
  48.     "blue=im.copy()"
  49.    ]
  50.   },
  51.   {
  52.    "cell_type": "code",
  53.    "execution_count": 12,
  54.    "metadata": {},
  55.    "outputs": [],
  56.    "source": [
  57.     "green=im.copy()"
  58.    ]
  59.   },
  60.   {
  61.    "cell_type": "code",
  62.    "execution_count": 13,
  63.    "metadata": {},
  64.    "outputs": [],
  65.    "source": [
  66.     "red=im.copy()"
  67.    ]
  68.   },
  69.   {
  70.    "cell_type": "markdown",
  71.    "metadata": {},
  72.    "source": [
  73.     "### The original image"
  74.    ]
  75.   },
  76.   {
  77.    "cell_type": "code",
  78.    "execution_count": 35,
  79.    "metadata": {},
  80.    "outputs": [],
  81.    "source": [
  82.     "cv2.namedWindow(\"random_image\",cv2.WINDOW_NORMAL)\n",
  83.     "cv2.resizeWindow(\"random_image\",590,332)\n",
  84.     "cv2.imshow(\"random_image\",im)\n",
  85.     "cv2.waitKey(0)\n",
  86.     "cv2.destroyAllWindows()"
  87.    ]
  88.   },
  89.   {
  90.    "cell_type": "markdown",
  91.    "metadata": {},
  92.    "source": [
  93.     "### Just to draw blue pic"
  94.    ]
  95.   },
  96.   {
  97.    "cell_type": "code",
  98.    "execution_count": 14,
  99.    "metadata": {},
  100.    "outputs": [],
  101.    "source": [
  102.     "blue[:, :, 1] = 0\n",
  103.     "blue[:, :, 2] = 0"
  104.    ]
  105.   },
  106.   {
  107.    "cell_type": "code",
  108.    "execution_count": 20,
  109.    "metadata": {},
  110.    "outputs": [],
  111.    "source": [
  112.     "cv2.namedWindow(\"random_image\",cv2.WINDOW_NORMAL)\n",
  113.     "cv2.resizeWindow(\"random_image\",590,332)\n",
  114.     "cv2.imshow(\"random_image\",blue)\n",
  115.     "cv2.waitKey(0)\n",
  116.     "cv2.destroyAllWindows()"
  117.    ]
  118.   },
  119.   {
  120.    "cell_type": "markdown",
  121.    "metadata": {},
  122.    "source": [
  123.     "### Just to draw green pic"
  124.    ]
  125.   },
  126.   {
  127.    "cell_type": "code",
  128.    "execution_count": 16,
  129.    "metadata": {},
  130.    "outputs": [],
  131.    "source": [
  132.     "green[:, :, 0] = 0\n",
  133.     "green[:, :, 2] = 0"
  134.    ]
  135.   },
  136.   {
  137.    "cell_type": "code",
  138.    "execution_count": 17,
  139.    "metadata": {},
  140.    "outputs": [],
  141.    "source": [
  142.     "cv2.namedWindow(\"random_image\",cv2.WINDOW_NORMAL)\n",
  143.     "cv2.resizeWindow(\"random_image\",590,332)\n",
  144.     "cv2.imshow(\"random_image\",green)\n",
  145.     "cv2.waitKey(0)\n",
  146.     "cv2.destroyAllWindows()"
  147.    ]
  148.   },
  149.   {
  150.    "cell_type": "markdown",
  151.    "metadata": {},
  152.    "source": [
  153.     "### Just to draw red pic"
  154.    ]
  155.   },
  156.   {
  157.    "cell_type": "code",
  158.    "execution_count": 18,
  159.    "metadata": {},
  160.    "outputs": [],
  161.    "source": [
  162.     "red[:, :, 0] = 0\n",
  163.     "red[:, :, 1] = 0"
  164.    ]
  165.   },
  166.   {
  167.    "cell_type": "code",
  168.    "execution_count": 19,
  169.    "metadata": {},
  170.    "outputs": [],
  171.    "source": [
  172.     "cv2.namedWindow(\"random_image\",cv2.WINDOW_NORMAL)\n",
  173.     "cv2.resizeWindow(\"random_image\",590,332)\n",
  174.     "cv2.imshow(\"random_image\",red)\n",
  175.     "cv2.waitKey(0)\n",
  176.     "cv2.destroyAllWindows()"
  177.    ]
  178.   },
  179.   {
  180.    "cell_type": "markdown",
  181.    "metadata": {},
  182.    "source": [
  183.     "### Just to remove one colour and draw image with two colours(blue and gree)"
  184.    ]
  185.   },
  186.   {
  187.    "cell_type": "code",
  188.    "execution_count": 25,
  189.    "metadata": {},
  190.    "outputs": [],
  191.    "source": [
  192.     "bg=im.copy()"
  193.    ]
  194.   },
  195.   {
  196.    "cell_type": "code",
  197.    "execution_count": 26,
  198.    "metadata": {},
  199.    "outputs": [],
  200.    "source": [
  201.     "bg[:, :, 2] = 0"
  202.    ]
  203.   },
  204.   {
  205.    "cell_type": "code",
  206.    "execution_count": 27,
  207.    "metadata": {},
  208.    "outputs": [],
  209.    "source": [
  210.     "cv2.namedWindow(\"random_image\",cv2.WINDOW_NORMAL)\n",
  211.     "cv2.resizeWindow(\"random_image\",590,332)\n",
  212.     "cv2.imshow(\"random_image\",bg)\n",
  213.     "cv2.waitKey(0)\n",
  214.     "cv2.destroyAllWindows()"
  215.    ]
  216.   },
  217.   {
  218.    "cell_type": "markdown",
  219.    "metadata": {},
  220.    "source": [
  221.     "### Blue and Red"
  222.    ]
  223.   },
  224.   {
  225.    "cell_type": "code",
  226.    "execution_count": 29,
  227.    "metadata": {},
  228.    "outputs": [],
  229.    "source": [
  230.     "br=im.copy()"
  231.    ]
  232.   },
  233.   {
  234.    "cell_type": "code",
  235.    "execution_count": 30,
  236.    "metadata": {},
  237.    "outputs": [],
  238.    "source": [
  239.     "br[:, :, 1] = 0"
  240.    ]
  241.   },
  242.   {
  243.    "cell_type": "code",
  244.    "execution_count": 31,
  245.    "metadata": {},
  246.    "outputs": [],
  247.    "source": [
  248.     "cv2.namedWindow(\"random_image\",cv2.WINDOW_NORMAL)\n",
  249.     "cv2.resizeWindow(\"random_image\",590,332)\n",
  250.     "cv2.imshow(\"random_image\",br)\n",
  251.     "cv2.waitKey(0)\n",
  252.     "cv2.destroyAllWindows()"
  253.    ]
  254.   },
  255.   {
  256.    "cell_type": "markdown",
  257.    "metadata": {},
  258.    "source": [
  259.     "### Green and Red"
  260.    ]
  261.   },
  262.   {
  263.    "cell_type": "code",
  264.    "execution_count": 7,
  265.    "metadata": {},
  266.    "outputs": [],
  267.    "source": [
  268.     "gr=im.copy()"
  269.    ]
  270.   },
  271.   {
  272.    "cell_type": "code",
  273.    "execution_count": 8,
  274.    "metadata": {},
  275.    "outputs": [],
  276.    "source": [
  277.     "gr[:, :, 0] = 0"
  278.    ]
  279.   },
  280.   {
  281.    "cell_type": "code",
  282.    "execution_count": 9,
  283.    "metadata": {},
  284.    "outputs": [],
  285.    "source": [
  286.     "cv2.namedWindow(\"random_image\",cv2.WINDOW_NORMAL)\n",
  287.     "cv2.resizeWindow(\"random_image\",590,332)\n",
  288.     "cv2.imshow(\"random_image\",gr)\n",
  289.     "cv2.waitKey(0)\n",
  290.     "cv2.destroyAllWindows()"
  291.    ]
  292.   },
  293.   {
  294.    "cell_type": "code",
  295.    "execution_count": 5,
  296.    "metadata": {},
  297.    "outputs": [
  298.     {
  299.      "data": {
  300.       "text/plain": [
  301.        "array([116,  22,  81], dtype=uint8)"
  302.       ]
  303.      },
  304.      "execution_count": 5,
  305.      "metadata": {},
  306.      "output_type": "execute_result"
  307.     }
  308.    ],
  309.    "source": [
  310.     "im[100][100]"
  311.    ]
  312.   },
  313.   {
  314.    "cell_type": "code",
  315.    "execution_count": 21,
  316.    "metadata": {},
  317.    "outputs": [],
  318.    "source": [
  319.     "reddish=im[:,:,0]"
  320.    ]
  321.   },
  322.   {
  323.    "cell_type": "code",
  324.    "execution_count": 22,
  325.    "metadata": {},
  326.    "outputs": [
  327.     {
  328.      "data": {
  329.       "text/plain": [
  330.        "(332, 590, 3)"
  331.       ]
  332.      },
  333.      "execution_count": 22,
  334.      "metadata": {},
  335.      "output_type": "execute_result"
  336.     }
  337.    ],
  338.    "source": [
  339.     "red.shape"
  340.    ]
  341.   },
  342.   {
  343.    "cell_type": "code",
  344.    "execution_count": 24,
  345.    "metadata": {},
  346.    "outputs": [],
  347.    "source": [
  348.     "cv2.imshow('red',reddish)\n",
  349.     "cv2.waitKey(0)\n",
  350.     "cv2.destroyAllWindows()"
  351.    ]
  352.   },
  353.   {
  354.    "cell_type": "code",
  355.    "execution_count": 11,
  356.    "metadata": {},
  357.    "outputs": [],
  358.    "source": [
  359.     "bgr=np.random.randint(255, size=(4,4,3), dtype=np.uint8)\n",
  360.     "cv2.namedWindow(\"random_image\",cv2.WINDOW_NORMAL)\n",
  361.     "cv2.resizeWindow(\"random_image\",1000,1000)\n",
  362.     "cv2.imshow(\"random_image\",bgr)\n",
  363.     "cv2.waitKey(0)\n",
  364.     "cv2.destroyAllWindows()"
  365.    ]
  366.   },
  367.   {
  368.    "cell_type": "code",
  369.    "execution_count": 12,
  370.    "metadata": {},
  371.    "outputs": [],
  372.    "source": [
  373.     "gr=np.random.randint(0,255, size=(4,4), dtype=np.uint8)\n",
  374.     "cv2.namedWindow(\"random_image\",cv2.WINDOW_NORMAL)\n",
  375.     "cv2.resizeWindow(\"random_image\",1000,1000)\n",
  376.     "cv2.imshow(\"random_image\",gr)\n",
  377.     "cv2.waitKey(0)\n",
  378.     "cv2.destroyAllWindows()"
  379.    ]
  380.   },
  381.   {
  382.    "cell_type": "code",
  383.    "execution_count": 5,
  384.    "metadata": {},
  385.    "outputs": [],
  386.    "source": [
  387.     "gray=cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)"
  388.    ]
  389.   },
  390.   {
  391.    "cell_type": "code",
  392.    "execution_count": 7,
  393.    "metadata": {},
  394.    "outputs": [],
  395.    "source": [
  396.     "cv2.namedWindow(\"random_image\",cv2.WINDOW_NORMAL)\n",
  397.     "cv2.resizeWindow(\"random_image\",1000,1000)\n",
  398.     "cv2.imshow(\"random_image\",im)\n",
  399.     "cv2.waitKey(0)\n",
  400.     "cv2.destroyAllWindows()"
  401.    ]
  402.   },
  403.   {
  404.    "cell_type": "code",
  405.    "execution_count": 8,
  406.    "metadata": {},
  407.    "outputs": [],
  408.    "source": [
  409.     "hsv=cv2.cvtColor(im,cv2.COLOR_BGR2HSV)"
  410.    ]
  411.   },
  412.   {
  413.    "cell_type": "code",
  414.    "execution_count": 9,
  415.    "metadata": {},
  416.    "outputs": [],
  417.    "source": [
  418.     "cv2.namedWindow(\"random_image\",cv2.WINDOW_NORMAL)\n",
  419.     "cv2.resizeWindow(\"random_image\",1000,1000)\n",
  420.     "cv2.imshow(\"random_image\",hsv)\n",
  421.     "cv2.waitKey(0)\n",
  422.     "cv2.destroyAllWindows()"
  423.    ]
  424.   },
  425.   {
  426.    "cell_type": "code",
  427.    "execution_count": null,
  428.    "metadata": {},
  429.    "outputs": [],
  430.    "source": []
  431.   }
  432.  ],
  433.  "metadata": {
  434.   "kernelspec": {
  435.    "display_name": "Python 3",
  436.    "language": "python",
  437.    "name": "python3"
  438.   },
  439.   "language_info": {
  440.    "codemirror_mode": {
  441.     "name": "ipython",
  442.     "version": 3
  443.    },
  444.    "file_extension": ".py",
  445.    "mimetype": "text/x-python",
  446.    "name": "python",
  447.    "nbconvert_exporter": "python",
  448.    "pygments_lexer": "ipython3",
  449.    "version": "3.7.1"
  450.   }
  451.  },
  452.  "nbformat": 4,
  453.  "nbformat_minor": 2
  454. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top