Home
A SIP User Manual - Pages Persos Chez.com
Contents
1. 22 7 Thanks 25 27 29 Chapter 1 Introduction SIP stands for Scilab Image Processing Its homepage is located at http siptoolbox sourceforge net This software was designed by Ricardo Fabbri lt rfabbriCif sc usp br gt in order to be able to use the power and tools of Scilab to treat images Let s look at what he says about his goals T have a dream that one day SIP SciLab will be the great free prototyping environment for image processing used and developed by people all over the world There are of course many obstacles to overcome before this dream come true SIP is free software GPL license and as such external contributions are welcome Several people have already contributed with other functions docu mentations or simply tests and bug reports I was already a Scilab user when I discovered SIP I had long searched for an easy way to treat images in various format jpg bmp As SIP uses ImageMagick every file format recognized by ImageMagick will be available in SIP This little book tries to help people start with SIP and develops some basic notions about image treatement Caution it does not describe all possibilities of SIP It applies mainly to version 0 3 so expect some modifications if you use another one I m developping with the Linux OS which I find much better than the M OS I love freedom The file path with Linux is noted with a slash whether Windows uses backslash so take ca
2. MODIFYING AN IMAGE BY ACTING ON THE SPECTRUM 23 gt xset window 5 xbasc imshow im2 Be careful the following is not equivalent gt IM3 fftshift IM z spectrum modification gt im3 real fft IM3 1 High frequencies must be in the center to allow a correct behavior of the reverse Fourier Transform You can find already built filters with the function mkfftfilter 24 CHAPTER 6 USING FFT IN IMAGES Original image Spectrum log representation Filter Resulting image Y A Zn m e Complementary filter Resulting image Chapter 7 Thanks Many thanks to Ricardo Fabbri for creating SIP for his encouragements and for his support I would also like to thank the following persons e J P Chancelier and the Scilab group who always took the time to answer my questions on Scilab e Daniel Droz for helping me start in photonics 25 26 CHAPTER 7 THANKS Chapter 8 References Here is a list of the books I used e J P PEREZ Optique fondements et applications 6e edition DUNOD e Chancelier Delebecque Gomez Goursat Nikoukhah Steer Introduction a SCILAB editions SPRINGER e C Rolland Latex par la pratique O REILLY 27 28 CHAPTER 8 REFERENCES Chapter 9 Index See next page Index colormap 13 strioscopy 21 convolution 17 coordinates 9 threshold truecolor 13
3. Note For Grayscale and Truecolor images mat values will be in the range 0 1 For indexed or paletted images mat values will be in the range 0 NC NC Number of Colors 2 5 Viewing an image gt xbasc imshow mat xbasc is to clear the current graphic window for grayscale or truecolor images For a pseudocolor image gt xbasc imshow mat map 2 6 Writing a matrix as an image file gt imwrite mat home druel test jpg be sure to have writing permissions on the destination repertory For pseudocolorimages you have to save the colormap too gt imwrite mat map home druel test jpg 2 7 NORMALISING 9 2 7 Normalising To darken an image gt dmat mat 0 6 gt xset window 2 xbasc imshow dmat gt max dmat returns 0 6 Now if you want the image to reoccupy the full range from 0 to 1 you can use the instruction normal gt nmat normal dmat 2 8 About coordinates The coordinates of an image start at the left upper corner Let s see it with an example gt image imread SIPDIR images ararauna jpg gt r c size image number of rows and columns gt image 10 1 1 draws a red line on row number 10 gt image 10 2 1 draws a green line on column number 10 10 CHAPTER 2 STARTING WITH SIP Chapter 3 Basic manipulations 3 1 Mean of 2 images gt mati imread imagel jpg mat2 imread image2 jp
4. 300 spectrum3 1 4 400 1 4 300 See the effects of a low pass and of a sharpener filter on the spectrum by gt image imconv image mkfilter mean or gt image imconv image mkfilter sh2 before calculating the fft 6 2 Modifying an image by acting on the spec trum The original image is restituted by gt im2 real fft IM 1 Before restitution we will apply a filter on the spectrum The simpliest filter is a binary one Usually these filters are in cylindrical coordinates Let s see that on a real example gt image gray_imread SIPDIR images ararauna jpg gt r c size image gt xset window 0 xbasc imshow image gt IM fft image 1 gt spectrum real IM conj IM gt xset window 1 xbasc imshow spectrum gt sp2 fftshift spectrum to center the spectrum gt xset window 2 xbasc imshow sp2 gt sp3 log sp2 1 gt xset window 3 xbasc imshow sp3 gt design the binary filter gt z zeros image gt x0 round r 2 radius 10 y0 round c 2 gt for x x0 radius x0 radius gt y round sqrt radius 2 x x0 2 gt z x y0 y y0ty 1 gt end gt if you want to inverse the filter gt z abs 1 z complementary filter gt xset window 4 xbasc imshow z gt IM2 IM fftshift z spectrum modification gt reverse transform gt im2 real fft IM2 1 6 2
5. Low pass filters reduce the variations of the luminosity in the image 2 examples e mean 1 9 1 9 1 9 1 9 1 9 1 9 1 9 1 9 1 9 e low pass 1 12 1 12 1 12 1 12 4 12 1 12 1 12 1 12 1 12 This one produces less correction than the mean kernel Laplaciens Using this kernel will show points of the image where intensity is varying quickly 2nd derivatve Because images are discrete and not continuous the second derivative can only be approximated here are 3 common approximative kernels e laplacel 1 1 4 1 1 e laplace2 1 1 1 1 8 1 5 2 OTHER FILTERS 19 e laplace3 E 2 1 2 4 2 E 2 1 5 1 3 Examples Original image Mean filtering Laplace1 filtering 5 2 Other filters These are non linear filters 5 2 1 Median filter Consider the following pixels HEE Bar 812 1 If you order these values you have 111223458 The median value is 2 the 5th position so the value 2 is affected to the central pixel This is a low pass filter used to despeckle an image it suppresses the high frequency noise without blurring too much the image Very usefull with images obtained with lasers because of speckle gt mmat mogrify mat median 1 perfo
6. The correct way is to get the 2D array and the colormap at the same time gt image map imread ararauna png gt xbasc imshow image map Display the colormap by gt pseudo ones 1 256 1 256 gt xbasc imshow pseudo map When writing this kind of picture don t forget to save the map by gt imwrite image map filename 4 3 4 I want to see more The introductory demo from Ricardo Fabbri is a visual explanation for col ormaps Launch it by exec SIPDEMO As colormaps are matrix you can perform operations on them Graycolormap Hotcolormap Hotcolormap reverse colormap for 1 hotcolormap hotcolormap 256 graycolormap 256 2 ararauna png 16CHAPTER 4 GRAYSCALES COLORS PSEUDOCOLORS AND CONVERSIONS 4 4 Converting a colored image to grayscale gt mat imread ararauna jpg gt gmat im2gray mat gt xset window 1 xbasc imshow gmat Or directly gt gmat gray_imread ararauna jpg Note typeof mat is hypermat color and typeof gmat is constant grayslevels 4 5 Thresholding To threshold an image at the 70 level the result will be rather dark gt bmat im2bw gmat 0 7 gt imshow bmat The bmat has only 2 values 0 or 1 Original image Threshold 70 Threshold 50 Chapter 5 Image filtering 5 1 Image c
7. A SIP User Manual for SIP version 0 3 rev 1 Jocelyn DRUEL jocelyn druell libertysurf fr February 12 2004 Contents al 1 Introduction 2 Starting with SIP 2 1 Installing SIP uo sion radar E E ee Ae ee re 2 3 A problem with memoryl Pee SOG ee ee owen ee ee ee 2 6 Writing a matrix as an image file 2 1 Normalising os coe e rd e RA 2 8 About coordinates 22 2 Co om nr 3 Basic manipulations 11 3 1 Mean of2imagesl 2 2 0 02 000 0000004 11 3 2 Multiplication of 2imagesl 2 22 2 2 nun 11 3 3 Addition or subtraction modulo 256 11 13 Penh er ea a rae dg ee eg 13 Munic pieles bv Sch da hs oS ok eee dados 13 AAA 14 SO IICA 4 3 1 Introduction 2222222 22mm nn 14 bs gh oe BS ws a re amp th ig ee Ruin 14 fe gan eo E 15 4 3 4 I want to see more J ooo a 15 E 16 4 5 Thresholding lt lt ee ee ee a 16 5 Image filtering 17 5 1 Image convolution o e en 17 MG aa gs hs A a e ces 17 5 1 2 Pre defined filters 2 22 222mm ren 18 E be Sede be ew ame a ea ee eas 19 52 Other filters 2 44 444044 2 220 2 badd eee ed es 19 4 CONTENTS 9 2 1 Median filter o 00000 19 5 2 2 Histogram equalization 19 6 Using fft in images 21 6 1 Observing the spectruM nn on 21 6 2 Modifying an image by acting on the spectrum
8. Druel 6 typeof 16 Fabbri fft 21 fitshift 21 gray_imread 16 grayscale histogram im2bw im2eray 16 imconv 17 imread 8 imshow license median 19 mkfftfilter 23 mkfilter 18 modulo II mogrify multiplication I normal 9 power 11 pseudocolor 13 RGB E6 spectrum stacksize 7 30
9. ents the spatial frequencies of the aper ture or Fourier spectrum Small details a slim slit will create high frequencies localised far from the center Usualy you modify the spectrum and then recreate an image of the initial object strioscopy In this first section we will just visualize the influence of several filters on the spectrum gt image zeros 400 300 gt image 180 220 145 155 1 gt xset window 0 xbasc imshow image gt IM sfft image 1 gt spectrum real IM conj IM calculates the image power spec trum gt xset window 1 xbasc imshow spectrum shows a spec trum with low frequencies located at each corner If you want to have low frequencies in the middle just gt spectrum2 sip_fftshift spectrum gt xset window 2 xbasc imshow spectrum2 Of course it s difficult to see all the frequencies The figure shows a very high central peak A better visualisation can be obtainde by two methods e use the log properties gt spectrum3 log spectrum2 1 21 22 CHAPTER 6 USING FFT IN IMAGES gt xset window 3 xbasc gt plot3d1 1 4 400 1 4 300 spectrum3 1 4 400 1 4 300 e or you can saturate the image gt spectrum3 spectrum2 threshold 1e3 gt spectrum3 find spectrum3 gt threshold threshold gt xset window 3 xbasc gt plot3d1 1 4 400 1 4
10. g gt mat_mean mati mat2 2 gt xbasc imshow mat_mean 3 2 Multiplication of 2 images Do not forget that multiplication of 2 matrix does not mean multiplying each element of the 1st matrix at the place i j by the element i j of the 2nd matrix To do so use the dot gt mat imread image jpg gt pmat mat mat calculates mat Compare with gt pmat mat mat 3 3 Addition or subtraction modulo 256 When using the function imread the result matrix is coded with doubles be tween 0 and 1 If you have 8bit images and want to perform an addition or subtraction modulo 256 ie 10 250 240 16 modulo 256 simply do gt mati imread imagel jpg mat2 imread image2 jpg gt mat_modulo uint8 mat1 255 uint8 mat2 255 gt mat_modulo double mat_modulo 255 in order to avoid future prob lems when trying to display mat_modulo 11 12 CHAPTER 3 BASIC MANIPULATIONS Chapter 4 Grayscales colors pseudocolors and conversions Advice pass this chapter if you re just discovering SIP and come back later to improve your knowledge and maybe solve your problems There are 3 types of images grayscale truecolor and pseudocolor 4 1 Grayscale images Grayscale images are 2D arrays of pixel values To read an image as a grayscale one you should use the gray_imread func tion instead of imread gt mat gray _imread onca gif gt xbasc imshow
11. mat gt size mat Usually you can have 16 bits values from 0 to 21 1 65535 or 8 bits values from 0 to 28 1 255 images SIP now stores these images in a 0 1 range If you prefer to work with 0 255 or 0 65535 ranges you just have to multiply mat by this factor 4 2 Truecolor images Truecolor images are made of 3 grayscale images one for each channel red green and blue gt mat imread ararauna jpg gt xbasc imshow mat 13 14CHAPTER 4 GRAYSCALES COLORS PSEUDOCOLORS AND CONVERSIONS gt size mat mat 1 is the red component mat 2 is the green component and mat 3 is the blue component 4 3 Pseudocolor images 4 3 1 Introduction Again let s do gt image imread onca gif gt min mat is 1 gt max mat is 256 This time the each pixel value points to a color defined in a colormap If you want to display this picture in gray do gt xbasc imshow mat graycolormap 256 to use a gray colormap with 256 values You may find that a gray display is a bit sad a colorful life is joyfuler So let s decide that e the low values near 1 will be displayed in dark red e the high values near 256 will be displayed in light yellow To perform it gt map hotcolormap 256 gt xset window 1 xbasc imshow image map Now we look in details at map it is a matrix with 3 columns and 256 rows The 1st row describe
12. onvolution Convolution of an image by a matrix is an easy operation the value of each pixel is modified depending of the values of its neighbours and of the coefficients of the convolution matrix or kernel Example Consider the following pixels Pays a 2 4 3 EHAE If you want to smooth the image ie to have less variations you can choose the following kernel ESEJE auli ESEJE The central pixel initial value 4 will now have the value 1x1 1x5 1x1 1x2 1x4 1x3 1x8 1x2 1x1 27 Of course to make sense you should divide by 9 sum of the coefficients of the kernel The central pixel takes then the value 3 The operation is repeated for each pixel of the image Several kernels exist depending on wheter you want to smooth the image or show quick variations of luminosity 5 1 1 General usage You ve got a matrix named mat Let s do a mean filtering gt kern 1 1 1 1 1 1 1 1 1 gt mat_conv 1 9 imconv mat kern gt xbasc imshow mat_conv 17 18 CHAPTER 5 IMAGE FILTERING 5 1 2 Pre defined filters Do not reinvent the wheel all the time There are several kernels which come with SIP gt mkfilter mean gt mat_conv imconv mat mkfilter mean gt xbasc imshow mat_conv PS if you ve got an interesting kernel please consider sending it to the SIP development list Low pass filters
13. re when copying examples from this book Feel free to send me comments and critics about it you could also use the development list to do so which is a better way to improve free software It s always pleasant to have feedback from other people About the license of this document well I not a license expert so P d like to say I wrote this manual on my spare time 6 CHAPTER 1 INTRODUCTION If you use some part of it at least don t claim it s your own work Author Jocelyn Druel Lycee Gustave Eiffel Labo photonique 96 rue Jules Lebleu 59280 ARMENTIERES FRANCE mail lt jocelyn druel1 libertysurf fr gt Chapter 2 Starting with SIP SIP uses ImageMagick to transform an image file in a matrix usable by Scilab The file formats usable are all those of ImageMagick JPEG TIFF BMP PNG and many more 2 1 Installing SIP Two versions of SIP are available e a binary one which is self containing which means you don t have to download other packages such as ImageMagick it s certainly the easiest way to start e asource distribution that you need to compile To load the SIP toolbox in Scilab please refer to the file INSTALL txt which comes with your SIP version Shortly once installed correctly launch Scilab and type exec loader sce You should have a message like SIP Scilab Image Processing loaded in your Scilab window Ready 2 2 Looking at a demo Launch exec SIPDEMO
14. rms a median filter The ra dius of the matrix used is 1 ie it s a 3x3 matrix 5 2 2 Histogram equalization This operation is often used to enhance the contrast of an image gt image gray_imread gra jpg gt xset window 0 imshow image gt fimage mogrify image equalize 20 CHAPTER 5 IMAGE FILTERING gt xset window 1 imshow fimage If you want to see histrogram modifications you can plot them with gt xset window 2 histplot 64 image gt xset window 3 histplot 64 fimage Original image Histogram ES 4 54 3054 254 154 salh 1 L 0 ted 24 34 44 Set bet T4 Histogram 6 3 5e 34 3034 H 234 1 34 Chapter 6 Using fft in images 6 1 Observing the spectrum The Fourier Transform gives informations about which frequencies are present in a signal spectrum In images small details correspond to high frequencies A great interest of the spectrum is that the original image can be re obtained using the spectrum Of course adding or suppressing frequencies in the spec trum will result in a modified image In optics the diffraction figure repres
15. s the color associated with the pixel value 1 the 2nd row is for the pixel value 2 The 3 columns represent the quantity of respectively red green and blue associated with each pixel value range 0 1 We can reverse the order of the map matrix ie we associate yellow to the pixel value 0 and red to the pixel value 255 gt invmap 256 1 1 1 3 map 1 1 256 1 3 reverse order gt xbasc imshow image invmap If you prefer blue colors you can do gt xbasc imshow image 1 hotcolormap 256 Standard Scilab version 2 7 has only 2 pre defined colormaps grayscale and hotcolormap But if you want more install the add on toolbox called Enrico very easy exec builder sce followed by exec loader sce Then display an image and launch es_demos Choose different colormaps and have fun 4 3 2 Viewing colormaps Just a practical example to view these beautiful colormaps gt pseudo ones 1 256 1 256 4 3 PSEUDOCOLOR IMAGES 15 gt xbasc imshow pseudo hotcolormap 256 4 3 3 Pseudocolor images Some images are coded as pseudocolor images with a complex colormap The following instructions gt image imread ararauna png gt xbasc imshow image graycolormap 256 does not show the expected bird in grayscale This is because the computer associates each pixel value with a gray level instead of associating it with a color described in the colormap
16. to have a little idea of SIP possibilities 2 3 A problem with memory As images are very big in memory occupation you should increase the stacksize in Scilab by using gt stacksize 3e7 the number after stacksize depends on the memory available on your pc 8 CHAPTER 2 STARTING WITH SIP If you don t want to write this instruction each time you start Scilab you can create or edit if it exists a file home my_user_name scilab which contains stacksize 3e7 This file is executed at each start of Scilab Alternatively to make this change system wide you can modify if you have sufficient permissions the scilab star file usually located in usr lib scilab so that every user has the same settings 2 4 Reading an image If you don t have images available you can use SIP ones by gt chdir SIPDIR images To read a grayscale or truecolor image gt mat imread ararauna jpg don t forget the if you don t want to see all the content of the matrix displayed on the screen The matrix called mat now contains the image ararauna jpg All tools availables in Scilab for matrix are instantly availables to treat images Wonderful If you have a pseudocolor image you must also get the colormap gt mat mapl imread ararauna png If you don t know what are pseudocolor images the chapter 1 Grayscales colors pseudocolors and conversions will give you more infos
Download Pdf Manuals
Related Search
Related Contents
Roland Dr. Rhytm DR-110 Owner`s manual Sartocheck® 3 plus Torcia da taglio meccanizzato Plasmarc 音楽に合わせて踊って Manual do usuário da Epson Stylus C45 3 Informações sobre a Vous rejoignez notre Association, voici notre engagement moral Samsung CLP-600 manual de utilizador Olympus AS-4000 Desktop Digital Voice Recorder Copyright © All rights reserved.
Failed to retrieve file