[Qgis-developer] Contrast Enhancement
Nejia
nejia at spaceyes.fr
Wed Nov 26 03:43:09 PST 2014
Hi,
You can see “Contrast Homogenizer” plugin that you can download it from Qgis Plugins - Official Repository <http://plugins.qgis.org/plugins/plugins.xml?qgis=2.6>
File contrastHomogenizer.py line 249
Regards,
Nejia
De : qgis-developer-bounces at lists.osgeo.org [mailto:qgis-developer-bounces at lists.osgeo.org] De la part de Alexia Mondot
Envoyé : mercredi 26 novembre 2014 01:08
À : qgis-developer at lists.osgeo.org
Objet : [Qgis-developer] Contrast Enhancement
Hi all,
I have some problems to apply new stretching values to my layer
I have a function which allows to adapt the stretching of my image without the raster layer properties dialog.
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.
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.
Here is my stretching code :
print canvas
print "layer :", theRasterLayer
# type of layer : raster, vector, other
typeOfLayer = theRasterLayer.type()
dataProvider = theRasterLayer.dataProvider()
# the layer has to be a raster layer
if typeOfLayer == 1 :
if (theRasterLayer.rasterType() == 0 ) and theRasterLayer.renderer():
[...]
elif theRasterLayer.rasterType() == 2 and theRasterLayer.renderer():
min_red, max_red = values[0]
min_green, max_green = values[1]
min_blue, max_blue = values[2]
redEnhancement = QgsContrastEnhancement( dataProvider.dataType( 0 ) )
greenEnhancement = QgsContrastEnhancement( dataProvider.dataType( 1 ) )
blueEnhancement = QgsContrastEnhancement( dataProvider.dataType( 2 ) )
#set stretch to min max
redEnhancement.setMinimumValue( min_red )
redEnhancement.setMaximumValue( max_red )
greenEnhancement.setMinimumValue( min_green )
greenEnhancement.setMaximumValue( max_green )
blueEnhancement.setMinimumValue( min_blue )
blueEnhancement.setMaximumValue( max_blue )
redEnhancement.setContrastEnhancementAlgorithm(1)
greenEnhancement.setContrastEnhancementAlgorithm(1)
blueEnhancement.setContrastEnhancementAlgorithm(1)
print "blue enhancement", blueEnhancement
print "blue max", blueEnhancement.maximumValue()
print "blue min", blueEnhancement.minimumValue()
theRasterLayer.renderer().setRedContrastEnhancement( redEnhancement)
theRasterLayer.renderer().setGreenContrastEnhancement( greenEnhancement )
theRasterLayer.renderer().setBlueContrastEnhancement( blueEnhancement)
theRasterLayer.triggerRepaint()
print theRasterLayer.renderer().blueContrastEnhancement()
print theRasterLayer.renderer().blueContrastEnhancement().minimumValue()
print theRasterLayer.renderer().blueContrastEnhancement().maximumValue()
canvas.refresh()
canvas.repaint()
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().
I know :
* both cases run this function.
* 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)
* these values are the good ones
* they aren't displayed in the raster layer properties dialog
* my raster layer source is ok
* when i do these steps on the QGIS python console with the layer iface.mapCanvas().currentLayer() which points to the same file, it works
layer = iface.mapCanvas().currentLayer()
blue_en = QgsContrastEnhancement( layer.dataProvider().dataType(2))
blue_en.setMinimumValue(150)
blue_en.setMaximumValue(350)
blue_en.setContrastEnhancementAlgorithm(1)
layer.renderer().setBlueContrastEnhancement(blue_en)
layer.triggerRepaint()
What have I missed ?
Thanks by advance,
Alexia
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20141126/650088aa/attachment.html>
More information about the Qgis-developer
mailing list