<div class="xblock xblock-public_view xblock-public_view-vertical" data-course-id="course-v1:digitalearthafrica+DEA101-fr+2021" data-init="VerticalStudentView" data-runtime-class="LmsRuntime" data-runtime-version="1" data-block-type="vertical" data-usage-id="block-v1:digitalearthafrica+DEA101-fr+2021+type@vertical+block@4baed3d49d4346ca848cba36c40fa869" data-request-token="b97ebf24edb511eea533472edd4aee3e" data-graded="False" data-has-score="False">
<div class="vert-mod">
<div class="vert vert-0" data-id="block-v1:digitalearthafrica+DEA101-fr+2021+type@html+block@43efcc655bb4443db6bcf2b5d3b63389">
<div class="xblock xblock-public_view xblock-public_view-html xmodule_display xmodule_HtmlBlock" data-course-id="course-v1:digitalearthafrica+DEA101-fr+2021" data-init="XBlockToXModuleShim" data-runtime-class="LmsRuntime" data-runtime-version="1" data-block-type="html" data-usage-id="block-v1:digitalearthafrica+DEA101-fr+2021+type@html+block@43efcc655bb4443db6bcf2b5d3b63389" data-request-token="b97ebf24edb511eea533472edd4aee3e" data-graded="False" data-has-score="False">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "HTMLModule"}
</script>
<p>Ce tutoriel présente matplotlib, une bibliothèque Python permettant de tracer des tableaux numpy sous forme d’images.</p>
<p>Suivez les instructions ci-dessous pour télécharger le tutoriel et l’ouvrir dans le Sandbox.</p>
<section id="Download-the-tutorial-notebook" style="box-sizing: border-box; color: #000000;">
<h2 style="box-sizing: border-box; margin-top: 0px; font-weight: bold; font-size: 24px; color: #336699; text-align: left;">Télécharger le notebook</h2>
<p style="box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px; font-size: 16px; text-align: left;"><a class="reference external" href="/assets/courseware/v1/5b5c6251a5e34536f055a256f57d4eb2/asset-v1:digitalearthafrica+DEA101-fr+2021+type@asset+block/03_download-matplotlib.ipynb" style="box-sizing: border-box; color: #2980b9; text-decoration-line: none; cursor: pointer;" target="[object Object]">Télécharger le notebook du tutoriel Python basics 3</a></p>
<p style="box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px; font-size: 16px; text-align: left;"><a download="Guinea_Bissau.JPG" href="/assets/courseware/v1/ac1f7795a228ab3c51b6709c9c88296d/asset-v1:digitalearthafrica+DEA101-fr+2021+type@asset+block/Guinea_Bissau.JPG" style="box-sizing: border-box; color: #2980b9; text-decoration-line: none; cursor: pointer;" target="[object Object]">Téléchargez le fichier image de l’exercice</a></p>
<p style="box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px; font-size: 16px; text-align: left;">Pour visualiser ce notebook sur le Sandbox, vous devrez d’abord le télécharger sur votre ordinateur, puis le charger sur le Sandbox. Assurez-vous d’avoir suivi les prérequis de configuration listés dans <a class="reference internal" href="/courses/course-v1:digitalearthafrica+DEA101-fr+2021/jump_to_id/9c210d02e6fe484a8ce67c67a1e9c2fa" target="[object Object]" style="box-sizing: border-box; color: #2980b9; text-decoration-line: none; cursor: pointer;">Les Bases de Python 1 : Jupyter</a>, puis suivez ces instructions :</p>
<ol class="arabic simple" style="box-sizing: border-box; margin-top: 0px; margin-bottom: 24px; padding-left: 0px; list-style-position: initial; list-style-image: initial; line-height: 24px; text-align: left;">
<li style="text-align: left; box-sizing: border-box; list-style: decimal; margin-left: 24px;">
<p style="text-align: left; box-sizing: border-box; line-height: 24px; margin: 0px; font-size: 16px;">Téléchargez le carnet de notes en cliquant sur le premier lien ci-dessus. Téléchargez l’image en cliquant sur le deuxième lien ci-dessus. Assurez-vous que le fichier image s'appelle <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">Guinea_Bissau.JPG</span></code>.</p>
</li>
<li style="text-align: left; box-sizing: border-box; list-style: decimal; margin-left: 24px;">
<p style="text-align: left; box-sizing: border-box; line-height: 24px; margin: 0px; font-size: 16px;">Dans le Sandbox, ouvrez le dossier <strong style="box-sizing: border-box;">Training</strong>.</p>
</li>
<li style="text-align: left; box-sizing: border-box; list-style: decimal; margin-left: 24px;">
<p style="text-align: left; box-sizing: border-box; line-height: 24px; margin: 0px; font-size: 16px;"> Cliquez sur le bouton <strong>Transférer les fichiers</strong> comme indiqué ci-dessous.</p>
</li>
</ol>
<p style="box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px; font-size: 16px; text-align: left;"><img alt="Upload button." class="no-scaled-link" src="https://learn.digitalearthafrica.org/asset-v1:digitalearthafrica+DEA101+2021+type@asset+block@05_solution_uploadbutton.png" style="box-sizing: border-box; border: 0px; vertical-align: middle; width: 400px;" /></p>
<ol class="arabic simple" start="4" style="box-sizing: border-box; margin-top: 0px; margin-bottom: 24px; padding-left: 0px; list-style-position: initial; list-style-image: initial; line-height: 24px; text-align: left;">
<li style="text-align: left; box-sizing: border-box; list-style: decimal; margin-left: 24px;">
<p style="text-align: left; box-sizing: border-box; line-height: 24px; margin: 0px; font-size: 16px;">Sélectionnez le notebook téléchargé à l’aide du navigateur de fichiers. Cliquez sur <strong>OK</strong>.</p>
</li>
<li style="text-align: left; box-sizing: border-box; list-style: decimal; margin-left: 24px;">
<p>Répétez l’opération pour télécharger le fichier image dans le dossier <strong>Training</strong>. Le téléchargement peut prendre un certain temps.</p>
</li>
<li style="text-align: left; box-sizing: border-box; list-style: decimal; margin-left: 24px;">Les deux fichiers apparaîtront dans le dossier <strong>Training</strong>. Double-cliquez sur le notebook de formation pour l’ouvrir et commencer le tutoriel.</li>
</ol>
<p style="box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px; font-size: 16px; text-align: left;">Vous pouvez maintenant utiliser le notebook comme une version interactive de cette page Web.</p>
<div class="admonition note" style="box-sizing: border-box; -webkit-font-smoothing: antialiased; padding: 12px; line-height: 24px; margin-bottom: 24px; background: #e7f2fa;">
<p class="admonition-title" style="box-sizing: border-box; line-height: 1; margin: -12px -12px 12px; font-size: inherit; font-family: inherit; font-variant-numeric: normal; font-variant-east-asian: normal; font-weight: bold; font-stretch: normal; text-rendering: auto; -webkit-font-smoothing: antialiased; color: #ffffff; background: #6ab0de; padding: 6px 12px; text-align: left;">Note</p>
<p style="box-sizing: border-box; line-height: 24px; margin: 0px; font-size: 16px; text-align: left;">Le notebook devrait ressembler au texte et au code ci-dessous. Cependant, les sorties du notebook d’exercices sont vides (c’est-à-dire qu’aucun résultat n’apparaît après les cellules de code). Suivez les instructions du cahier pour exécuter les cellules du notebook d’exercices. Reportez-vous à cette page pour vérifier que vos résultats sont similaires.</p>
</div>
</section>
</div>
</div>
</div>
<script type="text/javascript">
(function (require) {
require(['/static/js/dateutil_factory.be68acdff619.js?raw'], function () {
require(['js/dateutil_factory'], function (DateUtilFactory) {
DateUtilFactory.transform('.localized-datetime');
});
});
}).call(this, require || RequireJS.require);
</script>
<script>
function emit_event(message) {
parent.postMessage(message, '*');
}
</script>
</div>
<div class="xblock xblock-public_view xblock-public_view-vertical" data-course-id="course-v1:digitalearthafrica+DEA101-fr+2021" data-init="VerticalStudentView" data-runtime-class="LmsRuntime" data-runtime-version="1" data-block-type="vertical" data-usage-id="block-v1:digitalearthafrica+DEA101-fr+2021+type@vertical+block@d662100df561406e9b79bd0190e9d679" data-request-token="b97ebf24edb511eea533472edd4aee3e" data-graded="False" data-has-score="False">
<div class="vert-mod">
<div class="vert vert-0" data-id="block-v1:digitalearthafrica+DEA101-fr+2021+type@html+block@a27b3fcab4404ad1b9258954724ca857">
<div class="xblock xblock-public_view xblock-public_view-html xmodule_display xmodule_HtmlBlock" data-course-id="course-v1:digitalearthafrica+DEA101-fr+2021" data-init="XBlockToXModuleShim" data-runtime-class="LmsRuntime" data-runtime-version="1" data-block-type="html" data-usage-id="block-v1:digitalearthafrica+DEA101-fr+2021+type@html+block@a27b3fcab4404ad1b9258954724ca857" data-request-token="b97ebf24edb511eea533472edd4aee3e" data-graded="False" data-has-score="False">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "HTMLModule"}
</script>
<p style="box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px; font-size: 16px; text-align: left;">Nous allons utiliser une partie de matplotlib appelée <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">pyplot</span></code>. Nous pouvons importer pyplot en spécifiant qu’il vient de matplotlib. Nous abrégerons <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">pyplot</span></code> en <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">plt</span></code>.</p>
<div class="nbinput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px 0px 19px; width: 696.469px; padding-top: 5px; padding-bottom: 5px; color: #000000; font-family: Arial, sans-serif; text-align: left;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #307fc1;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[1]:
</pre>
</div>
</div>
<div class="input_area highlight-ipython3 notranslate" style="box-sizing: border-box; margin: 0px; flex: 1 1 0%; overflow: auto; border: 1px solid #e0e0e0; border-radius: 2px;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none;"><span style="box-sizing: border-box;"></span><span class="o" style="box-sizing: border-box; color: #666666;">%</span><span class="k" style="box-sizing: border-box; color: #008000; font-weight: bold;">matplotlib</span> inline
<span class="c1" style="box-sizing: border-box; color: #408080; font-style: italic;"># Génère des tracés sur la même page au lieu d'ouvrir une nouvelle fenêtre</span>
<span class="kn" style="box-sizing: border-box; color: #008000; font-weight: bold;">import</span> <span class="nn" style="box-sizing: border-box; color: #0000ff; font-weight: bold;">numpy</span> <span class="k" style="box-sizing: border-box; color: #008000; font-weight: bold;">as</span> <span class="nn" style="box-sizing: border-box; color: #0000ff; font-weight: bold;">np</span>
<span class="kn" style="box-sizing: border-box; color: #008000; font-weight: bold;">from</span> <span class="nn" style="box-sizing: border-box; color: #0000ff; font-weight: bold;">matplotlib</span> <span class="kn" style="box-sizing: border-box; color: #008000; font-weight: bold;">import</span> <span class="n" style="box-sizing: border-box;">pyplot</span> <span class="k" style="box-sizing: border-box; color: #008000; font-weight: bold;">as</span> <span class="n" style="box-sizing: border-box;">plt</span>
</pre>
</div>
</div>
</div>
<p style="box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px; font-size: 16px; color: #000000; text-align: left;">Les images sont des tableaux bidimensionnels contenant des pixels. Par conséquent, nous pouvons utiliser des tableaux bidimensionnels pour représenter des données d’image et les visualiser avec matplotlib.</p>
<h3></h3>
<div class="nboutput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px 0px 19px; width: 696.469px; padding-bottom: 5px; color: #000000; font-family: Arial, sans-serif;"></div>
</div>
</div>
<div class="vert vert-1" data-id="block-v1:digitalearthafrica+DEA101-fr+2021+type@html+block@909463e425ef49639c14f6d3f102c2f2">
<div class="xblock xblock-public_view xblock-public_view-html xmodule_display xmodule_HtmlBlock" data-course-id="course-v1:digitalearthafrica+DEA101-fr+2021" data-init="XBlockToXModuleShim" data-runtime-class="LmsRuntime" data-runtime-version="1" data-block-type="html" data-usage-id="block-v1:digitalearthafrica+DEA101-fr+2021+type@html+block@909463e425ef49639c14f6d3f102c2f2" data-request-token="b97ebf24edb511eea533472edd4aee3e" data-graded="False" data-has-score="False">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "HTMLModule"}
</script>
<h3>Créer et visualiser un tableau</h3>
<p style="box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px; font-size: 16px; color: #000000;">Dans l’exemple ci-dessous, nous allons utiliser la fonction numpy <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">arange</span></code> pour générer un tableau à 1 dimension rempli d’éléments de <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">0</span></code> à <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">99</span></code>, et ensuite le remodeler en un tableau à 2 dimensions en utilisant <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">reshape</span></code>.</p>
<div class="nbinput docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px; width: 696.469px; padding-top: 5px; color: #000000; font-family: Arial, sans-serif;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #307fc1;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[2]:
</pre>
</div>
</div>
<div class="input_area highlight-ipython3 notranslate" style="box-sizing: border-box; margin: 0px; flex: 1 1 0%; overflow: auto; border: 1px solid #e0e0e0; border-radius: 2px;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none;"><span style="box-sizing: border-box;"></span><span class="n" style="box-sizing: border-box;">arr</span> <span class="o" style="box-sizing: border-box; color: #666666;">=</span> <span class="n" style="box-sizing: border-box;">np</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">arange</span><span class="p" style="box-sizing: border-box;">(</span><span class="mi" style="box-sizing: border-box; color: #666666;">100</span><span class="p" style="box-sizing: border-box;">)</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">reshape</span><span class="p" style="box-sizing: border-box;">(</span><span class="mi" style="box-sizing: border-box; color: #666666;">10</span><span class="p" style="box-sizing: border-box;">,</span><span class="mi" style="box-sizing: border-box; color: #666666;">10</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="nb" style="box-sizing: border-box; color: #008000;">print</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">arr</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="n" style="box-sizing: border-box;">plt</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">imshow</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">arr</span><span class="p" style="box-sizing: border-box;">)</span>
</pre>
</div>
</div>
</div>
<div class="nboutput docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px; width: 696.469px; color: #000000; font-family: Arial, sans-serif;">
<div class="prompt empty docutils container" style="box-sizing: border-box; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;"></div>
<div class="output_area docutils container" style="box-sizing: border-box; flex: 1 1 0%; overflow: auto;">
<div class="highlight" style="box-sizing: border-box; background: unset; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none; color: unset;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none; background: unset;">[[ 0 1 2 3 4 5 6 7 8 9]
[10 11 12 13 14 15 16 17 18 19]
[20 21 22 23 24 25 26 27 28 29]
[30 31 32 33 34 35 36 37 38 39]
[40 41 42 43 44 45 46 47 48 49]
[50 51 52 53 54 55 56 57 58 59]
[60 61 62 63 64 65 66 67 68 69]
[70 71 72 73 74 75 76 77 78 79]
[80 81 82 83 84 85 86 87 88 89]
[90 91 92 93 94 95 96 97 98 99]]
</pre>
</div>
</div>
</div>
<div class="nboutput docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px; width: 696.469px; color: #000000; font-family: Arial, sans-serif;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #bf5b3d;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[2]:
</pre>
</div>
</div>
<div class="output_area docutils container" style="box-sizing: border-box; flex: 1 1 0%; overflow: auto;">
<div class="highlight" style="box-sizing: border-box; background: unset; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none; color: unset;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none; background: unset;"><matplotlib.image.AxesImage at 0x7f33279840f0>
</pre>
</div>
</div>
</div>
<div class="nboutput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px 0px 19px; width: 696.469px; padding-bottom: 5px; color: #000000; font-family: Arial, sans-serif;">
<div class="prompt empty docutils container" style="box-sizing: border-box; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;"></div>
<div class="output_area docutils container" style="box-sizing: border-box; flex: 1 1 0%; overflow: auto;"><img alt="../_images/python_basics_03_matplotlib_10_2.png" src="https://learn.digitalearthafrica.org/asset-v1:digitalearthafrica+DEA101+2021+type@asset+block@python_basics_03_matplotlib_10_2.png" style="box-sizing: border-box; border: 0px; vertical-align: middle; padding: 5px; margin: 0px;" /></div>
</div>
<p>Si vous vous souvenez du dernier tutoriel, nous étions capables d’adresser des régions d’un tableau numpy en utilisant la notation d’indexation par crochets <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">[</span> <span class="pre" style="box-sizing: border-box;">]</span></code>. Pour les tableaux multidimensionnels, nous pouvons utiliser une virgule, pour distinguer les axes.</p>
<div class="highlight-python notranslate" style="box-sizing: border-box; border: 1px solid #e1e4e5; overflow-x: auto; margin: 1px 0px 24px;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow-x: auto; margin: 0px; padding: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 12px; overflow: auto;"><span face="SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, Courier, monospace"><span style="box-sizing: border-box;"></span></span><span class="p" style="box-sizing: border-box;">[</span><span face="SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, Courier, monospace"> première dimension, deuxième dimension, troisième dimension, etc. </span><span class="p" style="box-sizing: border-box;">]</span><span face="SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, Courier, monospace">
</span></pre>
</div>
</div>
<p>Comme précédemment, nous utilisons les deux-points <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">:</span></code> pour désigner <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">[</span><span color="#e74c3c" face="SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, Courier, monospace"> </span><span class="pre" style="box-sizing: border-box;"><span color="#e74c3c" face="SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, Courier, monospace">début : Fin </span></span><span class="pre" style="box-sizing: border-box;">:</span><span color="#e74c3c" face="SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, Courier, monospace"> </span><span class="pre" style="box-sizing: border-box;">stride</span><span color="#e74c3c" face="SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, Courier, monospace"> </span><span class="pre" style="box-sizing: border-box;">]</span></code>. Nous pouvons le faire pour chaque dimension.</p>
<p>Par exemple, nous pouvons mettre à jour les valeurs de la partie gauche de ce tableau pour qu’elles soient égales à <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">1</span></code>.</p>
<div class="nbinput docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px; width: 696.469px; padding-top: 5px; color: #000000; font-family: Arial, sans-serif;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #307fc1;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[3]:
</pre>
</div>
</div>
<div class="input_area highlight-ipython3 notranslate" style="box-sizing: border-box; margin: 0px; flex: 1 1 0%; overflow: auto; border: 1px solid #e0e0e0; border-radius: 2px;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none;"><span style="box-sizing: border-box;"></span><span class="n" style="box-sizing: border-box;">arr</span> <span class="o" style="box-sizing: border-box; color: #666666;">=</span> <span class="n" style="box-sizing: border-box;">np</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">arange</span><span class="p" style="box-sizing: border-box;">(</span><span class="mi" style="box-sizing: border-box; color: #666666;">100</span><span class="p" style="box-sizing: border-box;">)</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">reshape</span><span class="p" style="box-sizing: border-box;">(</span><span class="mi" style="box-sizing: border-box; color: #666666;">10</span><span class="p" style="box-sizing: border-box;">,</span><span class="mi" style="box-sizing: border-box; color: #666666;">10</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="n" style="box-sizing: border-box;">arr</span><span class="p" style="box-sizing: border-box;">[:,</span> <span class="p" style="box-sizing: border-box;">:</span><span class="mi" style="box-sizing: border-box; color: #666666;">5</span><span class="p" style="box-sizing: border-box;">]</span> <span class="o" style="box-sizing: border-box; color: #666666;">=</span> <span class="mi" style="box-sizing: border-box; color: #666666;">1</span>
<span class="n" style="box-sizing: border-box;">plt</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">imshow</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">arr</span><span class="p" style="box-sizing: border-box;">)</span>
</pre>
</div>
</div>
</div>
<div class="nboutput docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px; width: 696.469px; color: #000000; font-family: Arial, sans-serif;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #bf5b3d;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[3]:
</pre>
</div>
</div>
<div class="output_area docutils container" style="box-sizing: border-box; flex: 1 1 0%; overflow: auto;">
<div class="highlight" style="box-sizing: border-box; background: unset; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none; color: unset;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none; background: unset;"><matplotlib.image.AxesImage at 0x7f33274d7198>
</pre>
</div>
</div>
</div>
<div class="nboutput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px 0px 19px; width: 696.469px; padding-bottom: 5px; color: #000000; font-family: Arial, sans-serif;">
<div class="prompt empty docutils container" style="box-sizing: border-box; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;"></div>
<div class="output_area docutils container" style="box-sizing: border-box; flex: 1 1 0%; overflow: auto;"><img alt="../_images/python_basics_03_matplotlib_12_1.png" src="https://learn.digitalearthafrica.org/asset-v1:digitalearthafrica+DEA101+2021+type@asset+block@python_basics_03_matplotlib_12_1.png" style="box-sizing: border-box; border: 0px; vertical-align: middle; padding: 5px; margin: 0px;" /></div>
</div>
<p>Les indices entre les crochets de <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">arr[:,</span> <span class="pre" style="box-sizing: border-box;">:5]</span></code> peuvent être décomposés comme suit :</p>
<div class="highlight-python notranslate" style="box-sizing: border-box; border: 1px solid #e1e4e5; overflow-x: auto; margin: 1px 0px 24px; color: #000000; font-family: Arial, sans-serif;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow-x: auto; margin: 0px; padding: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 12px; overflow: auto;"><span color="#000000" face="SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, Courier, monospace" style="color: #000000;"><span style="box-sizing: border-box;"></span></span><span class="p" style="box-sizing: border-box;">[</span><span color="#000000" face="SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, Courier, monospace" style="color: #000000;"> </span><span color="#666666" face="SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, Courier, monospace" style="color: #666666;">Début de la 1ère dimension : Fin de la 1ère dimension, Début de la 2ème dimension : Fin de la 2ème dimension</span><span color="#000000" face="SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, Courier, monospace" style="color: #000000;"> </span><span class="p" style="box-sizing: border-box;">]</span><span color="#000000" face="SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, Courier, monospace" style="color: #000000;">
</span></pre>
</div>
</div>
<p>Les dimensions sont séparées par la virgule <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">,</span></code>. Notre première dimension est l’axe vertical, et la deuxième dimension est l’axe horizontal. Leurs étendues sont marquées par les deux points <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">:</span></code>. Par conséquent :</p>
<div class="highlight-python notranslate" style="box-sizing: border-box; border: 1px solid #e1e4e5; overflow-x: auto; margin: 1px 0px 24px; color: #000000; font-family: Arial, sans-serif;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow-x: auto; margin: 0px; padding: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 12px; overflow: auto;"><span color="#000000" face="SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, Courier, monospace" style="color: #000000;"><span style="box-sizing: border-box;"></span></span><span class="p" style="box-sizing: border-box;">[</span><span color="#000000" face="SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, Courier, monospace" style="color: #000000;"> </span><span face="SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, Courier, monospace">Début vertical : Fin vertical, Début horizontal : Fin horizontal</span><span color="#000000" face="SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, Courier, monospace" style="color: #000000;"> </span><span class="p" style="box-sizing: border-box;">]</span><span color="#000000" face="SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, Courier, monospace" style="color: #000000;">
</span></pre>
</div>
</div>
<p>Si aucun index n’est saisi, le tableau prendra toutes les valeurs. Cela signifie que <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">[:,</span> <span class="pre" style="box-sizing: border-box;">:5]</span></code> donne :</p>
<div class="highlight-python notranslate" style="box-sizing: border-box; border: 1px solid #e1e4e5; overflow-x: auto; margin: 1px 0px 24px; color: #000000; font-family: Arial, sans-serif;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow-x: auto; margin: 0px; padding: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 12px; overflow: auto;"><span color="#000000" face="SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, Courier, monospace" style="color: #000000;"><span style="box-sizing: border-box;"></span></span><span class="p" style="box-sizing: border-box;">[</span><span color="#000000" face="SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, Courier, monospace" style="color: #000000;"> </span><span face="SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, Courier, monospace">Début vertical : Fin vertical, Début horizontal : Fin horizontal + 5</span><span color="#000000" face="SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, Courier, monospace" style="color: #000000;"> </span><span class="p" style="box-sizing: border-box;">]</span><span color="#000000" face="SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, Courier, monospace" style="color: #000000;">
</span></pre>
</div>
</div>
<p>L’index du tableau a donc sélectionné les 5 premiers pixels de la largeur, à toutes les valeurs verticales.</p>
<p>Voyons maintenant à quoi cela ressemble sur une image réelle.</p>
<h3></h3>
<div class="nboutput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px 0px 19px; width: 696.469px; padding-bottom: 5px; color: #000000; font-family: Arial, sans-serif;"></div>
</div>
</div>
<div class="vert vert-2" data-id="block-v1:digitalearthafrica+DEA101-fr+2021+type@html+block@12573953d9894888892dc48021918171">
<div class="xblock xblock-public_view xblock-public_view-html xmodule_display xmodule_HtmlBlock" data-course-id="course-v1:digitalearthafrica+DEA101-fr+2021" data-init="XBlockToXModuleShim" data-runtime-class="LmsRuntime" data-runtime-version="1" data-block-type="html" data-usage-id="block-v1:digitalearthafrica+DEA101-fr+2021+type@html+block@12573953d9894888892dc48021918171" data-request-token="b97ebf24edb511eea533472edd4aee3e" data-graded="False" data-has-score="False">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "HTMLModule"}
</script>
<h3>Importer des images à l'aide de pyplot</h3>
<div style="box-sizing: border-box;"><strong style="box-sizing: border-box;">Tip</strong>: Assurez-vous d’avoir téléchargé le fichier <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">Guinea_Bissau.JPG</span></code> dans votre dossier <strong>Training</strong> avec le notebook. Nous utiliserons ce fichier dans les prochaines étapes et exercices.</div>
<p>Nous pouvons utiliser la bibliothèque pyplot pour charger une image en utilisant la fonction matplotlib <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">imread</span></code>. <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">imread</span></code> lit un fichier image sous la forme d’un tableau numpy tridimensionnel. Cela permet de manipuler facilement le tableau.</p>
<p>Par convention, la première dimension correspond à l’axe vertical, la deuxième à l’axe horizontal et la troisième aux canaux rouge, vert et bleu de l’image. Par convention, les canaux rouge-vert-bleu prennent des valeurs comprises entre 0 et 255.</p>
<div class="nbinput docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px; width: 696.469px; padding-top: 5px; color: #000000; font-family: Arial, sans-serif;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #307fc1;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[4]:
</pre>
</div>
</div>
<div class="input_area highlight-ipython3 notranslate" style="box-sizing: border-box; margin: 0px; flex: 1 1 0%; overflow: auto; border: 1px solid #e0e0e0; border-radius: 2px;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none;"><span color="#000000" face="SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, Courier, monospace" style="color: #000000;"><span style="box-sizing: border-box;"></span></span><span class="n" style="box-sizing: border-box;">im</span><span color="#000000" face="SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, Courier, monospace" style="color: #000000;"> </span><span class="o" style="box-sizing: border-box; color: #666666;">=</span><span color="#000000" face="SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, Courier, monospace" style="color: #000000;"> </span><span class="n" style="box-sizing: border-box;">np</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">copy</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">plt</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">imread</span><span class="p" style="box-sizing: border-box;">(</span><span class="s1" style="box-sizing: border-box; color: #ba2121;">'Guinea_Bissau.JPG'</span><span class="p" style="box-sizing: border-box;">))</span><span color="#000000" face="SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, Courier, monospace" style="color: #000000;">
</span><span color="#408080" face="SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, Courier, monospace" style="color: #408080;"><i># Ce chemin de fichier (texte en rouge) indique que 'Guinea_Bissau.JPG' est dans le<br /># même dossier que le bloc-notes du didacticiel. Si vous avez déménagé ou
# renommé le fichier, le chemin du fichier doit être modifié pour correspondre.</i></span><span color="#000000" face="SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, Courier, monospace" style="color: #000000;">
</span><span class="n" style="box-sizing: border-box;">im</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">shape</span><span color="#000000" face="SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, Courier, monospace" style="color: #000000;">
</span></pre>
</div>
</div>
</div>
<div class="nboutput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px 0px 19px; width: 696.469px; padding-bottom: 5px; color: #000000; font-family: Arial, sans-serif;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #bf5b3d;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[4]:
</pre>
</div>
</div>
<div class="output_area docutils container" style="box-sizing: border-box; flex: 1 1 0%; overflow: auto;">
<div class="highlight" style="box-sizing: border-box; background: unset; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none; color: unset;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none; background: unset;">(590, 602, 3)
</pre>
</div>
</div>
</div>
<p><code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">Guinea_Bissau.JPG</span></code> est une image de Rio Baboque en Guinée-Bissau en 2018. Elle a été générée à partir des données du satellite Landsat 8.</p>
<p>Les résultats de la cellule ci-dessus montrent que l’image a une hauteur de 590 pixels, une largeur de 602 pixels et qu’elle possède 3 canaux. Ces trois canaux sont le rouge, le vert et le bleu (dans cet ordre).</p>
<p>Affichons cette image en utilisant la fonction pyplot<span style="font-size: 1em;"> </span><code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">imshow</span></code><span style="font-size: 1em;">.</span></p>
<div class="nbinput docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px; width: 696.469px; padding-top: 5px; color: #000000; font-family: Arial, sans-serif;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #307fc1;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[5]:
</pre>
</div>
</div>
<div class="input_area highlight-ipython3 notranslate" style="box-sizing: border-box; margin: 0px; flex: 1 1 0%; overflow: auto; border: 1px solid #e0e0e0; border-radius: 2px;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none;"><span style="box-sizing: border-box;"></span><span class="n" style="box-sizing: border-box;">plt</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">imshow</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">im</span><span class="p" style="box-sizing: border-box;">)</span>
</pre>
</div>
</div>
</div>
<div class="nboutput docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px; width: 696.469px; color: #000000; font-family: Arial, sans-serif;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #bf5b3d;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[5]:
</pre>
</div>
</div>
<div class="output_area docutils container" style="box-sizing: border-box; flex: 1 1 0%; overflow: auto;">
<div class="highlight" style="box-sizing: border-box; background: unset; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none; color: unset;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: pre; line-height: normal; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none; background: unset;"><matplotlib.image.AxesImage at 0x7f33273bb400>
</pre>
</div>
</div>
</div>
<p></p>
<p></p>
<div class="nboutput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px 0px 19px; width: 696.469px; padding-bottom: 5px; color: #000000; font-family: Arial, sans-serif;">
<div class="prompt empty docutils container" style="box-sizing: border-box; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;"></div>
<div class="output_area docutils container" style="box-sizing: border-box; flex: 1 1 0%; overflow: auto;"><img alt="../_images/python_basics_03_matplotlib_21_1.png" src="https://learn.digitalearthafrica.org/asset-v1:digitalearthafrica+DEA101+2021+type@asset+block@python_basics_03_matplotlib_21_1.png" style="box-sizing: border-box; border: 0px; vertical-align: middle; padding: 5px; margin: 0px; float: left;" /></div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
(function (require) {
require(['/static/js/dateutil_factory.be68acdff619.js?raw'], function () {
require(['js/dateutil_factory'], function (DateUtilFactory) {
DateUtilFactory.transform('.localized-datetime');
});
});
}).call(this, require || RequireJS.require);
</script>
<script>
function emit_event(message) {
parent.postMessage(message, '*');
}
</script>
</div>
<div class="xblock xblock-public_view xblock-public_view-vertical" data-course-id="course-v1:digitalearthafrica+DEA101-fr+2021" data-init="VerticalStudentView" data-runtime-class="LmsRuntime" data-runtime-version="1" data-block-type="vertical" data-usage-id="block-v1:digitalearthafrica+DEA101-fr+2021+type@vertical+block@b936b73fc8554f55a5f76032caeb94e0" data-request-token="b97ebf24edb511eea533472edd4aee3e" data-graded="False" data-has-score="False">
<div class="vert-mod">
<div class="vert vert-0" data-id="block-v1:digitalearthafrica+DEA101-fr+2021+type@html+block@e45910aa1a7f4c5492c75312ac9b358a">
<div class="xblock xblock-public_view xblock-public_view-html xmodule_display xmodule_HtmlBlock" data-course-id="course-v1:digitalearthafrica+DEA101-fr+2021" data-init="XBlockToXModuleShim" data-runtime-class="LmsRuntime" data-runtime-version="1" data-block-type="html" data-usage-id="block-v1:digitalearthafrica+DEA101-fr+2021+type@html+block@e45910aa1a7f4c5492c75312ac9b358a" data-request-token="b97ebf24edb511eea533472edd4aee3e" data-graded="False" data-has-score="False">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "HTMLModule"}
</script>
<section id="3.1-Let's-use-the-indexing-functionality-of-numpy-to-select-a-portion-of-this-image.-Select-the-top-right-corner-of-this-image-with-shape-(200,200)." style="box-sizing: border-box;">
<h3 style="box-sizing: border-box; margin-top: 0px; font-weight: bold; font-size: 20px; color: #336699; text-align: left;">3.1 Utilisons la fonctionnalité d’indexation de numpy pour sélectionner une partie de cette image. Sélectionnez le coin supérieur droit de cette image avec la forme <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 15px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">(200,200)</span></code>.<a class="headerlink" href="https://training.digitalearthafrica.org/en/latest/python_basics/03_matplotlib.html#3.1-Let's-use-the-indexing-functionality-of-numpy-to-select-a-portion-of-this-image.-Select-the-top-right-corner-of-this-image-with-shape-(200,200)." title="Permalink to this headline" style="box-sizing: border-box; color: #2980b9; text-decoration-line: none; cursor: pointer; display: inline-block; font-variant-numeric: normal; font-variant-east-asian: normal; font-weight: normal; font-stretch: normal; line-height: 1; font-family: inherit; font-size: 14px; text-rendering: auto; -webkit-font-smoothing: antialiased; visibility: hidden;"></a></h3>
<div style="box-sizing: border-box; text-align: left;">
<p style="box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px; font-size: 16px; text-align: left;"><b>Astuce: </b>Rappelez-vous qu’il y a trois dimensions dans cette image. Les deux points séparent les portées, et les virgules les dimensions.</p>
</div>
<div class="nbinput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px 0px 19px; width: 696.469px; padding-top: 5px; padding-bottom: 5px; text-align: left;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 16px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #307fc1;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[ ]:
</pre>
</div>
</div>
<div class="input_area highlight-ipython3 notranslate" style="box-sizing: border-box; margin: 0px; flex: 1 1 0%; overflow: auto; border: 1px solid #e0e0e0; border-radius: 2px;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 16px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none;"><span style="box-sizing: border-box;"></span># Nous avons déjà défini im ci-dessus, mais si ce n'est pas le cas,
# vous pouvez dé-commenter et exécuter la ligne suivante
# im = np.copy(plt.imread('Guinea_Bissau.JPG'))
# Remplissez les points d'interrogation avec les bons index
topright = im[?,?,?]
# Tracez votre résultat en utilisant imshow
plt.imshow(topright)
</pre>
</div>
</div>
</div>
<p style="box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px; font-size: 16px; text-align: left;">Si vous avez choisi le bon coin, il ne devrait pas y avoir beaucoup d’eau !</p>
</section>
<section id="3.2-Let's-have-a-look-at-one-of-the-pixels-in-this-image.-We-choose-the-top-left-corner-with-position-(0,0)-and-show-the-values-of-its-RGB-channels." style="box-sizing: border-box; color: #000000; font-family: Arial, sans-serif;">
<h3 style="box-sizing: border-box; margin-top: 0px; font-weight: bold; font-size: 20px; color: #336699;">3.2 Regardons l’un des pixels de cette image. Nous choisissons le coin supérieur gauche avec la position <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 15px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">(0,0)</span></code> et montrons les valeurs de ses canaux RVB.<a class="headerlink" href="https://training.digitalearthafrica.org/en/latest/python_basics/03_matplotlib.html#3.2-Let's-have-a-look-at-one-of-the-pixels-in-this-image.-We-choose-the-top-left-corner-with-position-(0,0)-and-show-the-values-of-its-RGB-channels." title="Permalink to this headline" style="box-sizing: border-box; color: #2980b9; text-decoration-line: none; cursor: pointer; display: inline-block; font-variant-numeric: normal; font-variant-east-asian: normal; font-weight: normal; font-stretch: normal; line-height: 1; font-family: inherit; font-size: 14px; text-rendering: auto; -webkit-font-smoothing: antialiased; visibility: hidden;"></a></h3>
<div class="nbinput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px 0px 19px; width: 696.469px; padding-top: 5px; padding-bottom: 5px;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 16px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #307fc1;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[ ]:
</pre>
</div>
</div>
<div class="input_area highlight-ipython3 notranslate" style="box-sizing: border-box; margin: 0px; flex: 1 1 0%; overflow: auto; border: 1px solid #e0e0e0; border-radius: 2px;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 16px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none;"><span style="box-sizing: border-box;"></span><span class="c1" style="box-sizing: border-box; color: #408080; font-style: italic;"># Exécutez cette cellule pour voir les valeurs des canaux de couleur</span>
<span class="n" style="box-sizing: border-box;">im</span><span class="p" style="box-sizing: border-box;">[</span><span class="mi" style="box-sizing: border-box; color: #666666;">0</span><span class="p" style="box-sizing: border-box;">,</span><span class="mi" style="box-sizing: border-box; color: #666666;">0</span><span class="p" style="box-sizing: border-box;">]</span>
</pre>
</div>
</div>
</div>
<p style="box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px; font-size: 16px; text-align: left;">La première valeur correspond à la composante rouge, la deuxième à la composante verte et la troisième à la composante bleue. <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">uint8</span></code> peut contenir des valeurs dans la plage <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">[0-255]</span></code> donc le pixel a beaucoup de rouge, un peu de vert, et peu de bleu. Ce pixel est d’une couleur sableuse jaune orangé.</p>
<p style="box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px; font-size: 16px; text-align: left;"><span face="Arial, sans-serif" style="font-family: Arial, sans-serif;">Maintenant, nous allons modifier l’image.</span></p>
</section>
<section id="What-happens-if-we-set-all-the-values-representing-the-blue-channel-to-the-maximum-value?" style="box-sizing: border-box; color: #000000; font-family: Arial, sans-serif;">
<h3 style="box-sizing: border-box; margin-top: 0px; font-weight: bold; font-size: 20px; color: #336699;">3.3 Que se passe-t-il si nous fixons toutes les valeurs représentant le canal bleu à la valeur maximale ?<a class="headerlink" href="https://training.digitalearthafrica.org/en/latest/python_basics/03_matplotlib.html#What-happens-if-we-set-all-the-values-representing-the-blue-channel-to-the-maximum-value?" title="Permalink to this headline" style="box-sizing: border-box; color: #2980b9; text-decoration-line: none; cursor: pointer; display: inline-block; font-variant-numeric: normal; font-variant-east-asian: normal; font-weight: normal; font-stretch: normal; line-height: 1; font-family: inherit; font-size: 14px; text-rendering: auto; -webkit-font-smoothing: antialiased; visibility: hidden;"></a></h3>
<div class="nbinput nblast docutils container" style="box-sizing: border-box; display: flex; align-items: flex-start; margin: 0px 0px 19px; width: 696.469px; padding-top: 5px; padding-bottom: 5px;">
<div class="prompt highlight-none notranslate" style="box-sizing: border-box; margin: 0px; width: 4.5ex; padding-top: 5px; position: relative; user-select: none;">
<div class="highlight" style="box-sizing: border-box; background: none; border: none; overflow-x: auto; margin: 0px 0.3ex 0px 0px; padding: 0px; box-shadow: none; position: absolute; right: 0px;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 16px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 0px; overflow: hidden; border: none; box-shadow: none; background: none; color: #307fc1;"><span style="box-sizing: border-box; border: none; padding: 0px; margin: 0px; box-shadow: none; background: none;"></span>[ ]:
</pre>
</div>
</div>
<div class="input_area highlight-ipython3 notranslate" style="box-sizing: border-box; margin: 0px; flex: 1 1 0%; overflow: auto; border: 1px solid #e0e0e0; border-radius: 2px;">
<div class="highlight" style="box-sizing: border-box; background: #f8f8f8; border: none; overflow: auto hidden; margin: 0px; padding: 0px; box-shadow: none;">
<pre style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 16px; white-space: pre; line-height: 1.4; margin-top: 0px; margin-bottom: 0px; padding: 5px; overflow: auto; border: none; box-shadow: none;"><span style="box-sizing: border-box;"></span><span class="c1" style="box-sizing: border-box; color: #408080; font-style: italic;"># Exécutez cette cellule pour définir toutes les valeurs du bande bleu sur 255</span>
<span class="c1" style="box-sizing: border-box; color: #408080; font-style: italic;"># On fait d'abord une copie pour éviter de modifier l'image d'origine</span>
<span class="n" style="box-sizing: border-box;">im2</span> <span class="o" style="box-sizing: border-box; color: #666666;">=</span> <span class="n" style="box-sizing: border-box;">np</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">copy</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">im</span><span class="p" style="box-sizing: border-box;">)</span>
<span class="n" style="box-sizing: border-box;">im2</span><span class="p" style="box-sizing: border-box;">[:,:,</span><span class="mi" style="box-sizing: border-box; color: #666666;">2</span><span class="p" style="box-sizing: border-box;">]</span> <span class="o" style="box-sizing: border-box; color: #666666;">=</span> <span class="mi" style="box-sizing: border-box; color: #666666;">255</span>
<span class="n" style="box-sizing: border-box;">plt</span><span class="o" style="box-sizing: border-box; color: #666666;">.</span><span class="n" style="box-sizing: border-box;">imshow</span><span class="p" style="box-sizing: border-box;">(</span><span class="n" style="box-sizing: border-box;">im2</span><span class="p" style="box-sizing: border-box;">)</span>
</pre>
</div>
</div>
</div>
<div style="box-sizing: border-box;">
<p style="box-sizing: border-box; line-height: 24px; margin: 0px 0px 24px; font-size: 16px; text-align: left;"><span style="color: #000000; font-family: Arial, sans-serif; font-size: 16px;">La notation de l’index <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">[:,:,2]</span></code> </span><span face="Arial, sans-serif" style="font-family: Arial, sans-serif;">sélectionne les pixels de toutes les hauteurs et de toutes les largeurs, mais uniquement le troisième bande de couleur.</span></p>
</div>
</section>
<section id="Can-you-modify-the-above-code-cell-to-set-all-red-values-to-the-maximum-value-of-255?" style="box-sizing: border-box; color: #000000; font-family: Arial, sans-serif;">
<h3 style="box-sizing: border-box; margin-top: 0px; font-weight: bold; font-size: 20px; color: #336699; text-align: left;">3.4 Pouvez-vous modifier la cellule de code ci-dessus pour fixer toutes les valeurs rouges à la valeur maximale de <code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 15px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">255</span></code>?</h3>
</section>
</div>
</div>
</div>
<script type="text/javascript">
(function (require) {
require(['/static/js/dateutil_factory.be68acdff619.js?raw'], function () {
require(['js/dateutil_factory'], function (DateUtilFactory) {
DateUtilFactory.transform('.localized-datetime');
});
});
}).call(this, require || RequireJS.require);
</script>
<script>
function emit_event(message) {
parent.postMessage(message, '*');
}
</script>
</div>
<div class="xblock xblock-public_view xblock-public_view-vertical" data-course-id="course-v1:digitalearthafrica+DEA101-fr+2021" data-init="VerticalStudentView" data-runtime-class="LmsRuntime" data-runtime-version="1" data-block-type="vertical" data-usage-id="block-v1:digitalearthafrica+DEA101-fr+2021+type@vertical+block@4b69f0cc7208429dae798e3d4e5fd2c3" data-request-token="b97ebf24edb511eea533472edd4aee3e" data-graded="False" data-has-score="False">
<div class="vert-mod">
<div class="vert vert-0" data-id="block-v1:digitalearthafrica+DEA101-fr+2021+type@html+block@fd0d6fcf596245cb804142e35bda975d">
<div class="xblock xblock-public_view xblock-public_view-html xmodule_display xmodule_HtmlBlock" data-course-id="course-v1:digitalearthafrica+DEA101-fr+2021" data-init="XBlockToXModuleShim" data-runtime-class="LmsRuntime" data-runtime-version="1" data-block-type="html" data-usage-id="block-v1:digitalearthafrica+DEA101-fr+2021+type@html+block@fd0d6fcf596245cb804142e35bda975d" data-request-token="b97ebf24edb511eea533472edd4aee3e" data-graded="False" data-has-score="False">
<script type="json/xblock-args" class="xblock-json-init-args">
{"xmodule-type": "HTMLModule"}
</script>
<p style="text-align: left;">Nous avons pratiqué avec succès l’indexation de tableaux numpy et l’affichage de ces tableaux à l’aide de matplotlib. Nous pouvons maintenant aussi lire un fichier dans Python en utilisant<span> </span><code class="docutils literal notranslate" style="box-sizing: border-box; font-family: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', Courier, monospace; font-size: 12px; white-space: nowrap; max-width: 100%; background-image: initial; background-color: #ffffff; border: 1px solid #e1e4e5; padding: 2px 5px; color: #e74c3c; overflow-x: auto;"><span class="pre" style="box-sizing: border-box;">pyplot.imread</span></code><span>. </span>La prochaine leçon couvre le nettoyage et le masquage des données.</p>
</div>
</div>
</div>
<script type="text/javascript">
(function (require) {
require(['/static/js/dateutil_factory.be68acdff619.js?raw'], function () {
require(['js/dateutil_factory'], function (DateUtilFactory) {
DateUtilFactory.transform('.localized-datetime');
});
});
}).call(this, require || RequireJS.require);
</script>
<script>
function emit_event(message) {
parent.postMessage(message, '*');
}
</script>
</div>