<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 14 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";
        color:#6633FF;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:70.85pt 70.85pt 70.85pt 70.85pt;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body bgcolor="#CCCCFF" lang=FR link=blue vlink=purple><div class=WordSection1><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Hi,<o:p></o:p></span></p><p class=MsoNormal><span style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>You can see “Contrast Homogenizer” plugin that you can download it from <a href="http://plugins.qgis.org/plugins/plugins.xml?qgis=2.6">Qgis Plugins - Official Repository</a><o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>File contrastHomogenizer.py line 249<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Regards,<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'>Nejia<o:p></o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><p class=MsoNormal><span lang=EN-US style='font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D'><o:p> </o:p></span></p><div><div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm'><p class=MsoNormal><b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowtext'>De :</span></b><span style='font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowtext'> qgis-developer-bounces@lists.osgeo.org [mailto:qgis-developer-bounces@lists.osgeo.org] <b>De la part de</b> Alexia Mondot<br><b>Envoyé :</b> mercredi 26 novembre 2014 01:08<br><b>À :</b> qgis-developer@lists.osgeo.org<br><b>Objet :</b> [Qgis-developer] Contrast Enhancement<o:p></o:p></span></p></div></div><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Hi all, <br><br>I have some problems to apply new stretching values to my layer<br><br>I have a function which allows to adapt the stretching of my image without the raster layer properties dialog.<br><br>When I open an image with my plugin, I display it on the canvas, I open my own histograms, and I can move the min max stretch of the 3 displayed bands.<br><br>It works well. But, when i save the project, i reopen it, I want to change the image stretching, it does nothing. The values are set, but it seems that the layer renderer is not updated.<br><br>Here is my stretching code :<br><br><br><o:p></o:p></p><p class=MsoNormal>    print canvas<br>    print "layer :", theRasterLayer<br>    <br>    # type of layer : raster, vector, other<br>    typeOfLayer = theRasterLayer.type()<br>         <br>    dataProvider = theRasterLayer.dataProvider()<br>    <br>    # the layer has to be a raster layer<br>    if typeOfLayer == 1 :<br>        if (theRasterLayer.rasterType() == 0 ) and theRasterLayer.renderer():<br>[...]<br>                <br>        elif theRasterLayer.rasterType() == 2  and theRasterLayer.renderer():<br>            min_red, max_red = values[0]<br>            min_green, max_green = values[1]<br>            min_blue, max_blue = values[2]<br>            <br>            redEnhancement = QgsContrastEnhancement( dataProvider.dataType( 0 ) )<br>            greenEnhancement = QgsContrastEnhancement( dataProvider.dataType( 1 ) )<br>            blueEnhancement = QgsContrastEnhancement( dataProvider.dataType( 2 ) )<br>            #set stretch to min max<br>            redEnhancement.setMinimumValue( min_red )<br>            redEnhancement.setMaximumValue( max_red )<br>            greenEnhancement.setMinimumValue( min_green )<br>            greenEnhancement.setMaximumValue( max_green )<br>            blueEnhancement.setMinimumValue( min_blue )<br>            blueEnhancement.setMaximumValue( max_blue )<br>            redEnhancement.setContrastEnhancementAlgorithm(1)<br>            greenEnhancement.setContrastEnhancementAlgorithm(1)<br>            blueEnhancement.setContrastEnhancementAlgorithm(1)<br>            <br>            print "blue enhancement", blueEnhancement<br>            print "blue max", blueEnhancement.maximumValue()<br>            print "blue min", blueEnhancement.minimumValue()<br>            <br>            theRasterLayer.renderer().setRedContrastEnhancement( redEnhancement)<br>            theRasterLayer.renderer().setGreenContrastEnhancement( greenEnhancement )<br>            theRasterLayer.renderer().setBlueContrastEnhancement( blueEnhancement)<br>              <br>        theRasterLayer.triggerRepaint()<br>        <br>        print theRasterLayer.renderer().blueContrastEnhancement()<br>        print theRasterLayer.renderer().blueContrastEnhancement().minimumValue()<br>        print theRasterLayer.renderer().blueContrastEnhancement().maximumValue()<br>    canvas.refresh()<br>    canvas.repaint()<o:p></o:p></p><p class=MsoNormal><br>In my case, the canvas, is the main canvas, I have checked I work on the good one comparing  the print canvas and the python console with iface.mapCanvas().<br><br>I know :<br>* both cases run this function.<br>* the minimum and maximum values of contrast enhancement are the same in my two prints (before and after the setXContrastEnhancement) (so the theRasterLayer.renderer().blueContrastEnhancement() seems to be well set)<br>* these values are the good ones<br>* they aren't displayed in the raster layer properties dialog<br>* my raster layer source is ok<br>* when i do these steps on the QGIS python console with the layer iface.mapCanvas().currentLayer() which points to the same file, it works<br><br><br><o:p></o:p></p><p class=MsoNormal>layer = iface.mapCanvas().currentLayer()<br>blue_en = QgsContrastEnhancement( layer.dataProvider().dataType(2))<br>blue_en.setMinimumValue(150)<br>blue_en.setMaximumValue(350)<br>blue_en.setContrastEnhancementAlgorithm(1)<br>layer.renderer().setBlueContrastEnhancement(blue_en)<br>layer.triggerRepaint()<o:p></o:p></p><p class=MsoNormal><br>What have I missed ?<br><br>Thanks by advance, <br>Alexia<o:p></o:p></p></div></body></html>