{"id":300,"date":"2020-12-10T00:47:34","date_gmt":"2020-12-10T00:47:34","guid":{"rendered":"http:\/\/med-space.org\/youssef-zaz-master\/?page_id=300"},"modified":"2020-12-14T01:21:38","modified_gmt":"2020-12-14T01:21:38","slug":"matlab-traitement-dimages","status":"publish","type":"page","link":"https:\/\/yzaz.net\/master\/matlab-traitement-dimages\/","title":{"rendered":"Matlab &#8211; Traitement d&#8217;images"},"content":{"rendered":"<p><strong>Histogramme<\/strong><br \/>\nCalcul et affichage d&#8217;histogramme d&#8217;une image:<\/p>\n<pre class=\"brush: matlabkey; title: ; notranslate\" title=\"\">\r\nImage=imread('cameraman.tif');\r\n[l,c]=size(Image);\r\nH=zeros(256,1);\r\nfor i=1:l\r\n   for j=1:c\r\n\t H(Image(i,j)+1)= H(Image(i,j)+1)+1;    \r\n    end \r\n  end\r\nbar(H)\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-305 size-full\" src=\"http:\/\/med-space.org\/youssef-zaz-master\/wp-content\/uploads\/2020\/12\/histogram.jpg\" alt=\"\" width=\"560\" height=\"420\" srcset=\"https:\/\/yzaz.net\/master\/wp-content\/uploads\/2020\/12\/histogram.jpg 560w, https:\/\/yzaz.net\/master\/wp-content\/uploads\/2020\/12\/histogram-300x225.jpg 300w, https:\/\/yzaz.net\/master\/wp-content\/uploads\/2020\/12\/histogram-326x245.jpg 326w, https:\/\/yzaz.net\/master\/wp-content\/uploads\/2020\/12\/histogram-80x60.jpg 80w\" sizes=\"(max-width: 560px) 100vw, 560px\" \/><br \/>\nAvec la fonction pr\u00e9definie:<\/p>\n<pre class=\"brush: matlabkey; title: ; notranslate\" title=\"\">\r\nimhist(Image)\r\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-304 size-full aligncenter\" src=\"http:\/\/med-space.org\/youssef-zaz-master\/wp-content\/uploads\/2020\/12\/histogram2.jpg\" alt=\"\" width=\"554\" height=\"466\" srcset=\"https:\/\/yzaz.net\/master\/wp-content\/uploads\/2020\/12\/histogram2.jpg 554w, https:\/\/yzaz.net\/master\/wp-content\/uploads\/2020\/12\/histogram2-300x252.jpg 300w\" sizes=\"(max-width: 554px) 100vw, 554px\" \/><\/p>\n<p><strong>Egalisation d&#8217;histogramme <\/strong><br \/>\nl&#8217;\u00e9galisation d&#8217;histogramme est une m\u00e9thode d&#8217;ajustement du contraste d&#8217;une image num\u00e9rique qui utilise l&#8217;histogramme. Elle consiste \u00e0 appliquer une transformation sur chaque pixel de l&#8217;image, et donc d&#8217;obtenir une nouvelle image \u00e0 partir d&#8217;une op\u00e9ration ind\u00e9pendante sur chacun des pixels. Cette transformation est construite \u00e0 partir de l&#8217;histogramme cumul\u00e9 de l&#8217;image de d\u00e9part.<\/p>\n<p>\u00c9tapes \u00e0 suivre<br \/>\n1. Calcul de l\u2019histogramme h(k) avec k \u0404[0; 255]<br \/>\n2. Histogramme cumul\u00e9<br \/>\n3. Transformation des niveaux de gris de l\u2019image<\/p>\n<p>En Matlab, la fonction pr\u00e9d\u00e9finie <strong>histeq<\/strong> permet d&#8217;obtenir l&#8217;histogramme \u00e9galis\u00e9 d&#8217;une image.<\/p>\n<pre class=\"brush: matlabkey; title: ; notranslate\" title=\"\">\r\nI = imread('pout.tif');\r\nimshow(I)\r\nimhist(I)\r\nI2 = histeq(I); \r\nimshow(I2)\r\nsubplot ( 2 , 2 , 1 ) ; imshow( I) ; title ( 'Image originale' ) ;\r\nsubplot ( 2 , 2 , 3 ) ; imhist(I) ; title ( 'Histogramme original' ) ;\r\nsubplot ( 2 , 2 , 2 ) ; imshow(I2) ; title ( 'Image trait\u00e9e (\u00e9galisation d''histogramme)' ) ;\r\nsubplot ( 2 , 2 , 4 ) ; imhist(I2) ; title ( 'Histogramme \u00e9galis\u00e9' ) ;\r\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-312 size-full\" src=\"http:\/\/med-space.org\/youssef-zaz-master\/wp-content\/uploads\/2020\/12\/egalisation-histogramme.jpg\" alt=\"\" width=\"1070\" height=\"627\" srcset=\"https:\/\/yzaz.net\/master\/wp-content\/uploads\/2020\/12\/egalisation-histogramme.jpg 1070w, https:\/\/yzaz.net\/master\/wp-content\/uploads\/2020\/12\/egalisation-histogramme-300x176.jpg 300w, https:\/\/yzaz.net\/master\/wp-content\/uploads\/2020\/12\/egalisation-histogramme-1024x600.jpg 1024w, https:\/\/yzaz.net\/master\/wp-content\/uploads\/2020\/12\/egalisation-histogramme-768x450.jpg 768w\" sizes=\"(max-width: 1070px) 100vw, 1070px\" \/><\/p>\n<h2>Ajout de bruit \u00e0 une image:<\/h2>\n<pre class=\"brush: matlabkey; title: ; notranslate\" title=\"\">\r\n% Read the test Image\r\nmygrayimg = imread('cameraman.tif');\r\nsubplot(2,3,1); \r\nimshow(mygrayimg); \r\ntitle('Original Image');\r\n\r\n% Add Salt and pepper noise with noise density 0.001\r\nsalt = imnoise(mygrayimg,'salt &amp;amp; pepper',0.001);\r\nsubplot(2,3,2);\r\nimshow(salt);\r\ntitle('Salt &amp;amp; Pepper Image (bruit impulsionnel faible)');\r\n\r\n% Add Salt and pepper noise with noise density 0.03\r\nsalt = imnoise(mygrayimg,'salt &amp;amp; pepper',0.03);\r\nsubplot(2,3,3);\r\nimshow(salt);\r\ntitle('Salt &amp;amp; Pepper Image (bruit impulsionnel fort)');\r\n\r\n\r\n% Add Gaussian noise with mean 0 and variance 0.003 \r\ngau = imnoise(mygrayimg, 'gaussian', 0, 0.003);\r\nsubplot(2,3,4);\r\nimshow(gau);\r\ntitle('Gaussian Image- mean 0 and variance 0.003');\r\n\r\n% Add Gaussian noise with mean 0 and variance 0.02 \r\ngau = imnoise(mygrayimg, 'gaussian', 0, 0.02);\r\nsubplot(2,3,5);\r\nimshow(gau);\r\ntitle('Gaussian Image- mean 0 and variance 0.02');\r\n\r\n% Original Image plus sinusoidal noise    \r\nsubplot(2,3,6);\r\n[x y] = meshgrid(1:256,1:256);\r\nmysinusoidalnoise = 15 * sin(2*pi\/14*x+2*pi\/14*y);\r\nmynoiseimg1 = double(mygrayimg) + mysinusoidalnoise;\r\nimshow(mynoiseimg1,[]);\r\ntitle('Generated Sinusoidal noise');\r\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-458 size-full\" src=\"http:\/\/med-space.org\/youssef-zaz-master\/wp-content\/uploads\/2020\/12\/bruit.jpg\" alt=\"\" width=\"1110\" height=\"615\" srcset=\"https:\/\/yzaz.net\/master\/wp-content\/uploads\/2020\/12\/bruit.jpg 1110w, https:\/\/yzaz.net\/master\/wp-content\/uploads\/2020\/12\/bruit-300x166.jpg 300w, https:\/\/yzaz.net\/master\/wp-content\/uploads\/2020\/12\/bruit-1024x567.jpg 1024w, https:\/\/yzaz.net\/master\/wp-content\/uploads\/2020\/12\/bruit-768x426.jpg 768w\" sizes=\"(max-width: 1110px) 100vw, 1110px\" \/><\/p>\n<p><strong>Filtre Moyen:<\/strong><\/p>\n<pre class=\"brush: matlabkey; title: ; notranslate\" title=\"\">\r\norg=imread('peppers.png');\r\nm = imnoise(org, 'gaussian', 0, 0.03); % Ajout d'un bruit blanc Gaussien, de moyenne nulle\r\nfilterWindow3 = ones(3) \/ 9;\r\nfilteredImage3 = imfilter(m, filterWindow3);\r\nfilterWindow5 = ones(5) \/ 25;\r\nfilteredImage5 = imfilter(m, filterWindow5);\r\nfilterWindow9 = ones(9) \/ 81;\r\nfilteredImage9 = imfilter(m, filterWindow9);\r\nfilterWindow15 = ones(15) \/ 225;\r\nfilteredImage15 = imfilter(m, filterWindow15);\r\nsubplot ( 2 , 3 , 1 ) ; imshow(org) ; title ( 'Image originale' ) ;\r\nsubplot ( 2 , 3 , 2 ) ; imshow(m) ; title ( 'Image bruit\u00e9e (bruit Gaussien)' ) ;\r\nsubplot ( 2 , 3 , 3 ) ; imshow(filteredImage3) ; title ( 'Image filtr\u00e9e (Moyen 3x3)');\r\nsubplot ( 2 , 3 , 4 ) ; imshow(filteredImage5) ; title ( 'Image filtr\u00e9e (Moyen 5x5)');\r\nsubplot ( 2 , 3 , 5 ) ; imshow(filteredImage9) ; title ( 'Image filtr\u00e9e (Moyen 9x9)');\r\nsubplot ( 2 , 3 , 6 ) ; imshow(filteredImage15) ; title ( 'Image filtr\u00e9e (Moyen 15x15)');\r\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-444 size-full\" src=\"http:\/\/med-space.org\/youssef-zaz-master\/wp-content\/uploads\/2020\/12\/filtre-moyen.jpg\" alt=\"\" width=\"1006\" height=\"567\" srcset=\"https:\/\/yzaz.net\/master\/wp-content\/uploads\/2020\/12\/filtre-moyen.jpg 1006w, https:\/\/yzaz.net\/master\/wp-content\/uploads\/2020\/12\/filtre-moyen-300x169.jpg 300w, https:\/\/yzaz.net\/master\/wp-content\/uploads\/2020\/12\/filtre-moyen-768x433.jpg 768w, https:\/\/yzaz.net\/master\/wp-content\/uploads\/2020\/12\/filtre-moyen-678x381.jpg 678w\" sizes=\"(max-width: 1006px) 100vw, 1006px\" \/><\/p>\n<p><strong>Filtre Gaussien:<\/strong><\/p>\n<pre class=\"brush: matlabkey; title: ; notranslate\" title=\"\">\r\nI = imread('cameraman.tif');\r\nIblur = imgaussfilt(I,2); % Image filtr\u00e9e avec un filtre Gaussiin- Sigma = 2\r\nsubplot ( 1 , 2 , 1 ) ; imshow(I) ; title ( 'Image originale');\r\nsubplot ( 1 , 2 , 2 ) ; imshow(Iblur) ; title ( 'image filtr\u00e9e avec un filtre Gaussien');\r\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-567 size-full\" src=\"http:\/\/med-space.org\/youssef-zaz-master\/wp-content\/uploads\/2020\/12\/gaussien.jpg\" alt=\"\" width=\"526\" height=\"232\" srcset=\"https:\/\/yzaz.net\/master\/wp-content\/uploads\/2020\/12\/gaussien.jpg 526w, https:\/\/yzaz.net\/master\/wp-content\/uploads\/2020\/12\/gaussien-300x132.jpg 300w\" sizes=\"(max-width: 526px) 100vw, 526px\" \/><\/p>\n<h2>Filtre m\u00e9dian:<\/h2>\n<pre class=\"brush: matlabkey; title: ; notranslate\" title=\"\">\r\nI = imread('eight.tif');\r\nJ = imnoise(I,'salt &amp;amp; pepper',0.02);\r\nK = medfilt2(J);\r\nsubplot ( 1 , 3 , 1 ) ; imshow(I) ; title ( 'Image originale');\r\nsubplot ( 1 , 3 , 2 ) ; imshow(J) ; title ( 'Image bruit\u00e9e');\r\nsubplot ( 1 , 3 , 3 ) ; imshow(K) ; title ( 'image filtr\u00e9e avec un filtre m\u00e9dian');\r\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-576 size-full\" src=\"http:\/\/med-space.org\/youssef-zaz-master\/wp-content\/uploads\/2020\/12\/median.jpg\" alt=\"\" width=\"974\" height=\"287\" srcset=\"https:\/\/yzaz.net\/master\/wp-content\/uploads\/2020\/12\/median.jpg 974w, https:\/\/yzaz.net\/master\/wp-content\/uploads\/2020\/12\/median-300x88.jpg 300w, https:\/\/yzaz.net\/master\/wp-content\/uploads\/2020\/12\/median-768x226.jpg 768w\" sizes=\"(max-width: 974px) 100vw, 974px\" \/><\/p>\n<h2>D\u00e9tection de contour:<\/h2>\n<pre class=\"brush: matlabkey; title: ; notranslate\" title=\"\">\r\nI = imread('coins.png');\r\nBW1 = edge(I,'sobel');\r\nBW2 = edge(I,'prewitt');\r\nBW3 = edge(I,'canny');\r\nsubplot ( 2 , 2 , 1 ) ; imshow(I) ; title ( 'Image originale' ) ;\r\nsubplot ( 2 , 2 , 2 ) ; imshow(BW1) ; title ( 'Contour avec Sobel' ) ;\r\nsubplot ( 2 , 2 , 3 ) ; imshow(BW2) ; title ( 'Contour avec prewitt' ) ;\r\nsubplot ( 2 , 2 , 4 ) ; imshow(BW3) ; title ( 'Contour avec Canny' ) ;\r\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-564 size-full\" src=\"http:\/\/med-space.org\/youssef-zaz-master\/wp-content\/uploads\/2020\/12\/contours.jpg\" alt=\"\" width=\"654\" height=\"587\" srcset=\"https:\/\/yzaz.net\/master\/wp-content\/uploads\/2020\/12\/contours.jpg 654w, https:\/\/yzaz.net\/master\/wp-content\/uploads\/2020\/12\/contours-300x269.jpg 300w\" sizes=\"(max-width: 654px) 100vw, 654px\" \/><\/p>\n<h2>Filtre morphologique (\u00e9rosion):<\/h2>\n<pre class=\"brush: matlabkey; title: ; notranslate\" title=\"\">\r\na=[\r\n0   0   0   1   0   0   0\r\n0   1   1   1   1   1   0\r\n0   1   0   1   1   1   0\r\n1   1   1   1   1   1   0\r\n0   0   1   1   1   1   0\r\n0   1   1   1   1   1   0\r\n0   0   0   0   0   1   0];\r\n \r\nst1=[1 1 1 \r\n     1 1 1\r\n     1 1 1];\r\nst2=[0 1 0 \r\n     1 1 1\r\n     0 1 0];\r\nst3=[0 1 0 \r\n     0 1 0\r\n     0 1 0]; \r\nst4=[0 0 0 \r\n     1 1 1\r\n     0 0 0]; \r\ni1= imerode(a,st1);\r\n i2= imerode(a,st2);\r\n i3= imerode(a,st3);\r\n i4= imerode(a,st4);\r\n subplot (2,3,1), imshow(a), title('original');\r\nsubplot (2,3,2), imshow(i1),  title ('erosion cube');\r\nsubplot (2,3,3), imshow(i2),  title ('erosion cercle');\r\nsubplot (2,3,4), imshow(i3),  title ('erosion |');\r\nsubplot (2,3,5), imshow(i4),  title ('erosion ---');\r\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-599 \" src=\"http:\/\/med-space.org\/youssef-zaz-master\/wp-content\/uploads\/2020\/12\/erosion6.jpg\" alt=\"\" width=\"621\" height=\"459\" \/><\/p>\n<h2><strong>Transform\u00e9e de Fourier Rapide sur l&#8217;image:<\/strong><\/h2>\n<pre class=\"brush: matlabkey; title: ; notranslate\" title=\"\">\r\n[f, p]=uigetfile('*','selection de fichier');\r\nS=imread(fullfile(p,f));\r\nsubplot(1,3,1); imshow (S);  title ( 'Image originale');\r\nFS=fft2(double(S)); \r\nmodule=abs(fftshift(FS)); \r\nMax=max(max(max(abs(module))));\r\nsubplot(1,3,2), imshow(module *255 \/Max);colormap gray ; title ( 'Spectre d''amplitude');\r\nphase=angle(fftshift(FS)); \r\nsubplot(1,3,3); imshow(phase,[-pi,pi]); colormap gray; title ( 'Spectre de phase');\r\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-583 size-full aligncenter\" src=\"http:\/\/med-space.org\/youssef-zaz-master\/wp-content\/uploads\/2020\/12\/fourier-1.jpg\" alt=\"\" width=\"728\" height=\"260\" srcset=\"https:\/\/yzaz.net\/master\/wp-content\/uploads\/2020\/12\/fourier-1.jpg 728w, https:\/\/yzaz.net\/master\/wp-content\/uploads\/2020\/12\/fourier-1-300x107.jpg 300w\" sizes=\"(max-width: 728px) 100vw, 728px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>Histogramme Calcul et affichage d&#8217;histogramme d&#8217;une image: &nbsp; Avec la fonction pr\u00e9definie: Egalisation d&#8217;histogramme l&#8217;\u00e9galisation d&#8217;histogramme est une m\u00e9thode d&#8217;ajustement du contraste d&#8217;une image num\u00e9rique <a class=\"mh-excerpt-more\" href=\"https:\/\/yzaz.net\/master\/matlab-traitement-dimages\/\" title=\"Matlab &#8211; Traitement d&#8217;images\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":221,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"_links":{"self":[{"href":"https:\/\/yzaz.net\/master\/wp-json\/wp\/v2\/pages\/300"}],"collection":[{"href":"https:\/\/yzaz.net\/master\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/yzaz.net\/master\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/yzaz.net\/master\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/yzaz.net\/master\/wp-json\/wp\/v2\/comments?post=300"}],"version-history":[{"count":14,"href":"https:\/\/yzaz.net\/master\/wp-json\/wp\/v2\/pages\/300\/revisions"}],"predecessor-version":[{"id":611,"href":"https:\/\/yzaz.net\/master\/wp-json\/wp\/v2\/pages\/300\/revisions\/611"}],"wp:attachment":[{"href":"https:\/\/yzaz.net\/master\/wp-json\/wp\/v2\/media?parent=300"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}