{"id":254,"date":"2020-12-09T18:55:23","date_gmt":"2020-12-09T18:55:23","guid":{"rendered":"http:\/\/med-space.org\/youssef-zaz-master\/?page_id=254"},"modified":"2020-12-12T14:35:41","modified_gmt":"2020-12-12T14:35:41","slug":"manipuler-images-matlab","status":"publish","type":"page","link":"https:\/\/yzaz.net\/master\/manipuler-images-matlab\/","title":{"rendered":"Matlab &#8211; Manipulation des images"},"content":{"rendered":"<p>Une image num\u00e9rique est d\u00e9finie par une fonction bidimensionnelle f(x, y), o\u00f9 x et y sont des coordonn\u00e9es spatiales. L&#8217;amplitude de &#8216;f&#8217; \u00e0 n&#8217;importe quelle coordonn\u00e9e est appel\u00e9e l&#8217;intensit\u00e9 de l&#8217;image \u00e0 ce point. Lorsque x, y et les l&#8217;amplitude de f sont toutes des quantit\u00e9s discr\u00e8tes finies, l\u2019image est consid\u00e9r\u00e9e num\u00e9rique.<\/p>\n<p>La num\u00e9risation des coordonn\u00e9es est appel\u00e9e &#8220;\u00e9chantillonnage&#8221;, tandis que la num\u00e9risation des valeurs d\u2019amplitude est appel\u00e9e &#8220;quantification&#8221;. Le r\u00e9sultat de l\u2019\u00e9chantillonnage et de la quantification est une matrice de nombres r\u00e9els.<\/p>\n<p>Une image num\u00e9ris\u00e9e est repr\u00e9sent\u00e9e en Matlab par:<\/p>\n<p><span class=\"katex-eq\" data-katex-display=\"false\">\n\n\\begin{bmatrix}\n\nf( 1,1) &amp; f( 1,2) &amp; \\cdots &amp; f( 1,N)\\\\\n\nf( 2,1) &amp; f( 2,2) &amp; &amp; f( 2,N)\\\\\n\n\\vdots &amp; &amp; &amp; \\vdots \\\\\n\nf( M,1) &amp; &amp; \\cdots &amp; f( M,N)\n\n\\end{bmatrix}\n\n<\/span><br \/>\nLes op\u00e9rations de lecture\/\u00e9criture des fichiers contenant des images sous Matlab sont simplifi\u00e9es gr\u00e2ce \u00e0 des fonctions pr\u00e9definies disponibles.<\/p>\n<p>Les images sont lues avec la fonction \u00abimread\u00bb.<br \/>\nExemple:<\/p>\n<pre class=\"brush: matlabkey; title: ; notranslate\" title=\"\">\r\nF = imread('peppers.png'); % si le repetoire de l'image n'est pas accessible, il faut indiquer le chemin d'acc\u00e8es.\r\n<\/pre>\n<p>Un certain nombre d&#8217;images sont fournies avec Matlab, <a href=\"http:\/\/med-space.org\/youssef-zaz-master\/images-matlab\/\">voir un \u00e9chantillon des plus utilis\u00e9es<\/a><\/p>\n<p>Pour afficher l&#8217;image:<\/p>\n<pre class=\"brush: matlabkey; title: ; notranslate\" title=\"\">\r\nimshow (F)\r\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-268 size-full aligncenter\" src=\"http:\/\/med-space.org\/youssef-zaz-master\/wp-content\/uploads\/2020\/12\/peppers-1.jpg\" alt=\"\" width=\"512\" height=\"384\" srcset=\"https:\/\/yzaz.net\/master\/wp-content\/uploads\/2020\/12\/peppers-1.jpg 512w, https:\/\/yzaz.net\/master\/wp-content\/uploads\/2020\/12\/peppers-1-300x225.jpg 300w, https:\/\/yzaz.net\/master\/wp-content\/uploads\/2020\/12\/peppers-1-326x245.jpg 326w, https:\/\/yzaz.net\/master\/wp-content\/uploads\/2020\/12\/peppers-1-80x60.jpg 80w\" sizes=\"(max-width: 512px) 100vw, 512px\" \/><\/p>\n<p>Pour r\u00e9cup\u00e9rer la dimension de l&#8217;image:<\/p>\n<pre class=\"brush: matlabkey; title: ; notranslate\" title=\"\">\r\nsize (F)\r\n<\/pre>\n<pre>ans =\r\n   384   512     3\r\n<\/pre>\n<p>La hauteur de l&#8217;image: 384<br \/>\nLa largeur de l&#8217;image: 512<br \/>\n3: indique les 3 matrices relatives aux 3 couleurs R, V et B.<\/p>\n<p><strong>D\u00e9composition de l&#8217;image en 3 composantes Rouge, verte et bleu.<\/strong>:<\/p>\n<pre class=\"brush: matlabkey; title: ; notranslate\" title=\"\">\r\nf = imread ( 'peppers.png' ) ; \r\nn = size (f) ;\r\nn = n(1:2);\r\nfigure ;\r\nf1 = cat ( 3, f (:,:,1) , zeros (n) , zeros (n) ) ;\r\nf2 = cat ( 3, zeros (n) , f (:,:,2),zeros(n)) ;\r\nf3 = cat ( 3, zeros (n) , zeros (n) , f (:,:,3)) ;\r\nsubplot ( 2 , 2 , 1 ) ; imshow( f) ; title ( 'peppers image' ) ;\r\nsubplot ( 2 , 2 , 2 ) ; imshow( f1) ; title ( 'composante rouge' ) ;\r\nsubplot ( 2 , 2 , 3 ) ; imshow( f2) ; title ( 'composante verte' ) ;\r\nsubplot ( 2 , 2 , 4 ) ; imshow( f3) ; title ( 'composante bleue' ) ;\r\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-309 size-full\" src=\"http:\/\/med-space.org\/youssef-zaz-master\/wp-content\/uploads\/2020\/12\/decomposition.jpg\" alt=\"\" width=\"666\" height=\"539\" srcset=\"https:\/\/yzaz.net\/master\/wp-content\/uploads\/2020\/12\/decomposition.jpg 666w, https:\/\/yzaz.net\/master\/wp-content\/uploads\/2020\/12\/decomposition-300x243.jpg 300w\" sizes=\"(max-width: 666px) 100vw, 666px\" \/><\/p>\n<p><strong>Construire une image \u00e0 partir d&#8217;une matrice:<\/strong><br \/>\nExemple 1:<\/p>\n<pre class=\"brush: matlabkey; title: ; notranslate\" title=\"\">\r\nrow = 256;\r\ncol = 256;\r\nimg = zeros(row, col);\r\nimg(100:105, :) = 0.5;\r\nimg(:, 100:105) = 1;\r\nfigure;\r\nimshow(img);\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-296 aligncenter\" src=\"http:\/\/med-space.org\/youssef-zaz-master\/wp-content\/uploads\/2020\/12\/untitled2-2.jpg\" alt=\"\" width=\"258\" height=\"259\" srcset=\"https:\/\/yzaz.net\/master\/wp-content\/uploads\/2020\/12\/untitled2-2.jpg 258w, https:\/\/yzaz.net\/master\/wp-content\/uploads\/2020\/12\/untitled2-2-150x150.jpg 150w\" sizes=\"(max-width: 258px) 100vw, 258px\" \/><\/p>\n<p>Exemple 2:<br \/>\nUne image de bruit:<\/p>\n<pre class=\"brush: matlabkey; title: ; notranslate\" title=\"\">\r\nrow = 256;\r\ncol = 256;\r\nimg = rand(row, col);\r\nimg = round(img);\r\nfigure;\r\nimshow(img);\r\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-298 aligncenter\" src=\"http:\/\/med-space.org\/youssef-zaz-master\/wp-content\/uploads\/2020\/12\/untitled3-1.jpg\" alt=\"\" width=\"256\" height=\"256\" srcset=\"https:\/\/yzaz.net\/master\/wp-content\/uploads\/2020\/12\/untitled3-1.jpg 256w, https:\/\/yzaz.net\/master\/wp-content\/uploads\/2020\/12\/untitled3-1-150x150.jpg 150w\" sizes=\"(max-width: 256px) 100vw, 256px\" \/><\/p>\n<p><strong>Rotation d&#8217;une image<\/strong><br \/>\ncode Matlab pour pivoter une image:<\/p>\n<pre class=\"brush: matlabkey; title: ; notranslate\" title=\"\">\r\nI = imread('onion.png');\r\nJ = imrotate(I,35);\r\nsubplot(1,2,1); imshow(I); title('image I' );\r\nsubplot(1,2,2); imshow(J); title('image J (rotation de 35\u00b0)');\r\n<\/pre>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-403 size-full\" src=\"http:\/\/med-space.org\/youssef-zaz-master\/wp-content\/uploads\/2020\/12\/rotation-img.jpg\" alt=\"\" width=\"667\" height=\"296\" srcset=\"https:\/\/yzaz.net\/master\/wp-content\/uploads\/2020\/12\/rotation-img.jpg 667w, https:\/\/yzaz.net\/master\/wp-content\/uploads\/2020\/12\/rotation-img-300x133.jpg 300w\" sizes=\"(max-width: 667px) 100vw, 667px\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>Une image num\u00e9rique est d\u00e9finie par une fonction bidimensionnelle f(x, y), o\u00f9 x et y sont des coordonn\u00e9es spatiales. L&#8217;amplitude de &#8216;f&#8217; \u00e0 n&#8217;importe quelle <a class=\"mh-excerpt-more\" href=\"https:\/\/yzaz.net\/master\/manipuler-images-matlab\/\" title=\"Matlab &#8211; Manipulation des images\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":210,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"_links":{"self":[{"href":"https:\/\/yzaz.net\/master\/wp-json\/wp\/v2\/pages\/254"}],"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=254"}],"version-history":[{"count":14,"href":"https:\/\/yzaz.net\/master\/wp-json\/wp\/v2\/pages\/254\/revisions"}],"predecessor-version":[{"id":407,"href":"https:\/\/yzaz.net\/master\/wp-json\/wp\/v2\/pages\/254\/revisions\/407"}],"wp:attachment":[{"href":"https:\/\/yzaz.net\/master\/wp-json\/wp\/v2\/media?parent=254"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}