diff options
author | Prashant S | 2020-04-14 10:25:32 +0530 |
---|---|---|
committer | GitHub | 2020-04-14 10:25:32 +0530 |
commit | 06b09e7d29d252fb2f5a056eeb8bd1264ff6a333 (patch) | |
tree | 2b1df110e24ff0174830d7f825f43ff1c134d1af /Digital_Image_Processing_by_S_Jayaraman/11-Colur_Image_Processing.ipynb | |
parent | abb52650288b08a680335531742a7126ad0fb846 (diff) | |
parent | 476705d693c7122d34f9b049fa79b935405c9b49 (diff) | |
download | all-scilab-tbc-books-ipynb-master.tar.gz all-scilab-tbc-books-ipynb-master.tar.bz2 all-scilab-tbc-books-ipynb-master.zip |
Initial commit
Diffstat (limited to 'Digital_Image_Processing_by_S_Jayaraman/11-Colur_Image_Processing.ipynb')
-rw-r--r-- | Digital_Image_Processing_by_S_Jayaraman/11-Colur_Image_Processing.ipynb | 426 |
1 files changed, 426 insertions, 0 deletions
diff --git a/Digital_Image_Processing_by_S_Jayaraman/11-Colur_Image_Processing.ipynb b/Digital_Image_Processing_by_S_Jayaraman/11-Colur_Image_Processing.ipynb new file mode 100644 index 0000000..bc4db43 --- /dev/null +++ b/Digital_Image_Processing_by_S_Jayaraman/11-Colur_Image_Processing.ipynb @@ -0,0 +1,426 @@ +{ +"cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Chapter 11: Colur Image Processing" + ] + }, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 11.12: Read_a_Colour_image_and_separate_the_colour_image_into_red_green_and_blue_planes.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Caption:Read a Colour image and separate the colour image into: red,green\n", +"//and blue planes\n", +"//Fig.11.12: MATLAB Example2\n", +"//page592\n", +"clc;\n", +"close;\n", +"RGB = imread('E:\DIP_JAYARAMAN\Chapter11\peppers.png'); //SIVP toolbox\n", +"a1 = RGB;\n", +"b1 = RGB;\n", +"c1 = RGB;\n", +"a1(:,:,1)=0;\n", +"b1(:,:,2)=0;\n", +"c1(:,:,3)=0;\n", +"figure(1)\n", +"ShowColorImage(RGB, 'Original Color Image'); //IPD toolbox\n", +"figure(2)\n", +"ShowColorImage(a1, 'Red Missing');\n", +"figure(3)\n", +"ShowColorImage(b1, 'Green Missing');\n", +"figure(4)\n", +"ShowColorImage(c1, 'Blue Missing');" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 11.16: Compute_the_histogram_of_the_colour_image.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Caption:Compute the histogram of the colour image\n", +"//Fig.11.16: MATLAB Example3\n", +"//page595\n", +"clc;\n", +"close;\n", +"I = imread('E:\DIP_JAYARAMAN\Chapter11\lavender.jpg'); //SIVP toolbox\n", +"figure(1)\n", +"ShowColorImage(I, 'Original Color Image'); //IPD toolbox\n", +"J = im2double(I);\n", +"[index,map] = RGB2Ind(I); //IPD toolbox\n", +"pixels = prod(size(index));\n", +"hsv = rgb2hsv(J);\n", +"h = hsv(:,1);\n", +"s = hsv(:,2);\n", +"v = hsv(:,3);\n", +"//Finds location of black and white pixels\n", +"darks = find(v<0.2);\n", +"lights = find(s<0.05 & v>0.85);\n", +"h([darks lights])=-1;\n", +"//Gets the number of all pixels for each colour bin\n", +"black_pixels = length(darks)/pixels;\n", +"white_pixels = length(lights)/pixels;\n", +"red = length(find((h > .9167 | h <= .083) & h ~= -1))/pixels;\n", +"yellow = length(find(h > .083 & h <= .25))/pixels;\n", +"green = length(find(h > .25 & h <= .4167))/pixels;\n", +"cyan = length(find(h > .4167 & h <= .5833))/pixels;\n", +"blue = length(find(h > .5833 & h <= .75))/pixels;\n", +"magenta = length(find(h > .75 & h <= .9167))/pixels;\n", +"//Plots histogram\n", +"figure(2)\n", +"a=gca();\n", +"a.data_bounds=[0,0;8,1]\n", +"n = 0:0.1:1;\n", +"plot2d2(n,red*ones(1,length(n)),5)\n", +"n1 = 1:0.1:2;\n", +"plot2d2(n1,yellow*ones(1,length(n)),7)\n", +"n2 = 2:0.1:3;\n", +"plot2d2(n2,green*ones(1,length(n)),8)\n", +"n3 = 3:0.1:4;\n", +"plot2d2(n3,cyan*ones(1,length(n)),9)\n", +"n4 = 4:0.1:5;\n", +"plot2d2(n4,blue*ones(1,length(n)),2)\n", +"n5 = 5:0.1:6;\n", +"plot2d2(n5,magenta*ones(1,length(n)),3)\n", +"n6 = 6:0.1:7;\n", +"plot2d2(n6,white_pixels*ones(1,length(n)),0)\n", +"n7 = 7:0.1:8\n", +"plot2d2(n7,black_pixels*ones(1,length(n)),5)" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 11.18: Perform_histogram_equalisation_of_the_given_RGB_image.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Caption:Perform histogram equalisation of the given RGB image\n", +"//Fig.11.18: MATLAB Example4\n", +"//page596\n", +"clc;\n", +"close;\n", +"a = imread('E:\DIP_JAYARAMAN\Chapter11\peppers.png'); //SIVP toolbox\n", +"//conversion of RGB to YIQ format\n", +"b = rgb2ntsc(a);\n", +"//Histogram equalisation of Y component alone\n", +"b(:,:,1) = \n", +"//conversion of YIQ to RGB format\n", +"c = ntsc2rgb(b);\n", +"figure(1)\n", +"ShowColorImage(a, 'Original Image'); //IPD toolbox\n", +"figure(2)\n", +"ShowColorImage(c, 'Histogtram equalized Image'); //IPD toolbox" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 11.21: This_program_performs_median_filtering_of_the_colour_image.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Caption:This program performs median filtering of the colour image\n", +"//Fig.11.21: MATLAB Example5\n", +"//page598\n", +"clc;\n", +"close;\n", +"a = imread('E:\DIP_JAYARAMAN\Chapter11\peppers.png'); //SIVP toolbox\n", +"b = imnoise(a, 'salt & pepper', 0.2);\n", +"c(:,:,1)= MedianFilter(b(:,:,1), [3 3]);\n", +"c(:,:,2)= MedianFilter(b(:,:,2), [3 3]); \n", +"c(:,:,3)= MedianFilter(b(:,:,3), [3 3]); \n", +"figure(1)\n", +"ShowColorImage(a, 'Original Image'); //IPD toolbox\n", +"figure(2)\n", +"ShowColorImage(b, 'corrupted Image'); //IPD toolbox\n", +"figure(3)\n", +"ShowColorImage(c, 'Median Filtered Image'); //IPD toolbox" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 11.24: Fitlering_only_the_luminance_component.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Caption:Fitlering only the luminance component\n", +"//Fig.11.24: MATLAB Example6\n", +"//page599\n", +"clc;\n", +"close;\n", +"a = imread('E:\DIP_JAYARAMAN\Chapter11\peppers.png'); //SIVP toolbox\n", +"//conversion of RGB to YIQ format\n", +"yiq = rgb2ntsc(a);\n", +"//Extract the Y component alone\n", +"b = yiq(:,:,1);\n", +"h = [-1,-1,-1;-1,8,-1;-1,-1,-1];\n", +"//Perform high pass filtering only on Y component\n", +"c1 = conv2d2(b,h);\n", +"[m,n]= size(b);\n", +"for i =1:m\n", +" for j=1:n\n", +" D(i,j)= c1(i,j);\n", +" end\n", +"end\n", +"yiq(:,:,1)=D;\n", +"//convert YIQ to RGB format\n", +"a1 = ntsc2rgb(yiq);\n", +"figure(1)\n", +"ShowColorImage(a, 'Original Image'); //IPD toolbox\n", +"figure(2)\n", +"ShowColorImage(a1, 'High Pass filtered Image'); //IPD toolbox" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 11.28: Perform_gamma_correction_for_the_given_colour_image.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Caption:Perform gamma correction for the given colour image\n", +"//Fig.11.28: MATLAB Example7\n", +"//page603\n", +"close;\n", +"clear;\n", +"clc;\n", +"I = imread('E:\DIP_JAYARAMAN\Chapter11\ararauna.png'); //SIVP toolbox\n", +"gamma_Value = 0.5;\n", +"max_intensity = 255; //for uint8 image\n", +"//Look up table creation\n", +"LUT = max_intensity.*(([0:max_intensity]./max_intensity).^gamma_Value);\n", +"LUT = floor(LUT);\n", +"//Mapping of input pixels into lookup table values\n", +"K = double(I)+1;\n", +"J = zeros(I);\n", +"[m,n,p]= size(K);\n", +"for i = 1:m\n", +" for j =1:n\n", +" for k = 1:p\n", +" J(i,j,k)= LUT(K(i,j,k));\n", +" end\n", +" end\n", +"end\n", +"figure(1)\n", +"ShowColorImage(I, 'Original Image'); //IPD toolbox\n", +"figure(2)\n", +"ShowColorImage(uint8(J), 'Gamma Corrected Image'); //IPD toolbox" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 11.30: Perform_Pseudo_Colouring_Operation.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Caption:Perform Pseudo-Colouring Operation\n", +"//Fig.11.30\n", +"//page604\n", +"close;\n", +"clear;\n", +"clc;\n", +"K = imread('E:\DIP_JAYARAMAN\Chapter11\lenna.jpg'); //SIVP toolbox\n", +"[m,n]= size(K);\n", +"I = uint8(K);\n", +"for i = 1:m\n", +" for j =1:n\n", +" if (I(i,j)>=0 & I(i,j)<50)\n", +" J(i,j,1)=I(i,j)+50;\n", +" J(i,j,2)=I(i,j)+100;\n", +" J(i,j,3)=I(i,j)+10;\n", +" elseif (I(i,j)>=50 & I(i,j)<100)\n", +" J(i,j,1)=I(i,j)+35;\n", +" J(i,j,2)=I(i,j)+128;\n", +" J(i,j,3)=I(i,j)+10;\n", +" elseif(I(i,j)>=100 & I(i,j)<150)\n", +" J(i,j,1)=I(i,j)+152;\n", +" J(i,j,2)=I(i,j)+130;\n", +" J(i,j,3)=I(i,j)+15;\n", +" elseif(I(i,j)>=150 & I(i,j)<200)\n", +" J(i,j,1)=I(i,j)+50;\n", +" J(i,j,2)=I(i,j)+140;\n", +" J(i,j,3)=I(i,j)+25;\n", +" elseif(I(i,j)>=200 & I(i,j)<=256)\n", +" J(i,j,1)=I(i,j)+120;\n", +" J(i,j,2)=I(i,j)+160;\n", +" J(i,j,3)=I(i,j)+45;\n", +" end\n", +" end\n", +"end\n", +"figure(1)\n", +"ShowImage(K, 'Original Image'); //IPD toolbox\n", +"figure(2)\n", +"ShowColorImage(J, 'Pseudo Coloured Image'); //IPD toolbox" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 11.32: Read_an_RGB_image_and_segment_it_using_the_threshold_method.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Caption:Read an RGB image and segment it using the threshold method\n", +"//Fig11.32\n", +"//Page605\n", +"close;\n", +"clc;\n", +"I = imread('E:\DIP_JAYARAMAN\Chapter11\ararauna.png'); //SIVP toolbox\n", +"//Conversion of RGB to YCbCr\n", +"b = rgb2ycbcr_1(I); //SIVP toolbox\n", +"[m,n,p]=size(b);\n", +"b = uint8(b);\n", +"//Threshold is applied only to Cb component\n", +"mask = b(:,:,2)>120;\n", +"figure(1)\n", +"ShowColorImage(I,'Original Image'); //IPD toolbox\n", +"figure(2)\n", +"ShowImage(mask, 'Segmented Image'); //IPD toolbox" + ] + } +, +{ + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Example 11.4: Read_an_RGB_image_and_extract_the_three_colour_components_red_green_blue.sce" + ] + }, + { +"cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], +"source": [ +"//Caption:Read an RGB image and extract the three colour components: red,green\n", +"//and blue\n", +"//Fig.11.4: MATLAB Example1\n", +"//page588\n", +"clc;\n", +"close;\n", +"RGB = imread('E:\DIP_JAYARAMAN\Chapter11\peppers.png'); //SIVP toolbox\n", +"R = RGB;\n", +"G = RGB;\n", +"B = RGB;\n", +"R(:,:,2)=0;\n", +"R(:,:,3)=0;\n", +"G(:,:,1)=0;\n", +"G(:,:,3)=0;\n", +"B(:,:,1)=0;\n", +"B(:,:,2)=0;\n", +"figure(1)\n", +"ShowColorImage(RGB, 'Original Color Image'); //IPD toolbox\n", +"title('Original Color Image');\n", +"figure(2)\n", +"ShowColorImage(R, 'Red Component');\n", +"figure(3)\n", +"ShowColorImage(G, 'Green Component');\n", +"figure(4)\n", +"ShowColorImage(B, 'Blue Component');" + ] + } +], +"metadata": { + "kernelspec": { + "display_name": "Scilab", + "language": "scilab", + "name": "scilab" + }, + "language_info": { + "file_extension": ".sce", + "help_links": [ + { + "text": "MetaKernel Magics", + "url": "https://github.com/calysto/metakernel/blob/master/metakernel/magics/README.md" + } + ], + "mimetype": "text/x-octave", + "name": "scilab", + "version": "0.7.1" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +} |