|
From: Luke R. <luk...@ve...> - 2005-10-19 00:53:28
|
Hello all,
I've been using the OpenEV sample application for some time now, and I'm
really happy with all of its built-in functionality. I'm now starting
to try my hand at making some simple modifications. One of my goals is
to add a tool that will allow users to "zero" all pixels in an image
with the same value as that of the pixel directly under the cursor (to
make it easier to remove specific classes from thematic imagery).
Currently, I am working on a small sub-step to this goal, which would be
to create a toolbar button that will zero all pixels with a specific
(hardcoded) value. The toolbar button is working fine, and I've started
on the callback function. So far, my code looks like this, and it seems
to be working up until the point where I try to save the modified data
back to the image. Does anybody have any ideas what I am doing wrong,
or if there is a more correct / simpler way to do this? Also, what is
the appropriate way to contribute modified code back to the project?
def class_delete_all_cb(self, *args):
""" Zero all pixels of class 4 """
gvutils.warning('Testing: This should delete all pixels of class 4')
self.make_active()
try:
view = self.viewarea
layer = view.active_layer()
dataset = layer.get_parent().get_dataset()
band = dataset.GetRasterBand(1)
except:
gvutils.warning('Error: Obtaining raster band failed')
try:
data = band.ReadAsArray()
except:
gvutils.warning('Error: Reading data failed')
try:
pixels_changed = 0
for data_row in data:
for data_val in data_row:
if (data_val == 4):
data_val = 0
pixels_changed = pixels_changed + 1
print "Pixels deleted: ", pixels_changed
except:
gvutils.warning('Error: Clearing array failed')
try:
band.WriteArray(data)
except:
gvutils.warning('Error: Writing data failed')
Thanks for your help!
Luke Roth
|