Sobel edge detection

1026
7
04-17-2014 07:42 AM
MaherAL_ZUHAIRI
New Contributor
Hello,
Can anybody tell what is wrong with this:
it works in python window, but when I make it script tool does not work
please help

..............................................

import scipy.ndimage
import numpy,arcpy
import string
import PIL.Image

arcpy.env.overwriteOutput = True

inpRaster=arcpy.GetParameterAsText(0)

desc = arcpy.Describe(inpRaster)
layersource = desc.catalogPath

imageread=scipy.ndimage.imread(layersource)
sobelimage=scipy.ndimage.sobel(imageread,0)

outimage=PIL.Image.fromarray(sobelimage)
Out=outimage.save('D:\Outputs\sobel.jpg')
Tags (2)
0 Kudos
7 Replies
DanPatterson_Retired
MVP Emeritus
what is the error message?
0 Kudos
MaherAL_ZUHAIRI
New Contributor
what is the error message?


No error message, just after click OK to execute the text file open (Code file).........
0 Kudos
GerryGabrisch
Occasional Contributor III
Try running this version with an error handler and see if you get an error message to post.



# ---------------------------------------------------------------------------
# NeighborScore.py
# Created on: 2013-01-07 13:26:35.00000
# Updated on: 2014-02-12
# Description: Will create output tables based on the average and sum of neighboring polygon values
# ---------------------------------------------------------------------------

#B comment: I believe this is as the script was delivered on Feb 12 2014
#B comment: See most recent NeighborScore_Working version for most current version
try:  
   
    import sys
    import traceback
    import scipy.ndimage
    import numpy,arcpy
    import string
    import PIL.Image

    arcpy.env.overwriteOutput = True

    inpRaster=arcpy.GetParameterAsText(0)
    
    desc = arcpy.Describe(inpRaster)
    layersource = desc.catalogPath
    
    imageread=scipy.ndimage.imread(layersource)
    sobelimage=scipy.ndimage.sobel(imageread,0)
    
    outimage=PIL.Image.fromarray(sobelimage)
    Out=outimage.save('D:\Outputs\sobel.jpg') 
        
except arcpy.ExecuteError: 
    print "error"
    msgs = arcpy.GetMessages(2) 
    arcpy.AddError(msgs)  
    print msgs
except:
    print "error"
    tb = sys.exc_info()[2]
    tbinfo = traceback.format_tb(tb)[0]
    pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()[1])
    msgs = "ArcPy ERRORS:\n" + arcpy.GetMessages(2) + "\n"
    arcpy.AddError(pymsg)
    arcpy.AddError(msgs)
    print pymsg + "\n"
    print msgs
0 Kudos
MaherAL_ZUHAIRI
New Contributor
Try running this version with an error handler and see if you get an error message to post.



# ---------------------------------------------------------------------------
# NeighborScore.py
# Created on: 2013-01-07 13:26:35.00000
# Updated on: 2014-02-12
# Description: Will create output tables based on the average and sum of neighboring polygon values
# ---------------------------------------------------------------------------

#B comment: I believe this is as the script was delivered on Feb 12 2014
#B comment: See most recent NeighborScore_Working version for most current version
try:  
   
    import sys
    import traceback
    import scipy.ndimage
    import numpy,arcpy
    import string
    import PIL.Image

    arcpy.env.overwriteOutput = True

    inpRaster=arcpy.GetParameterAsText(0)
    
    desc = arcpy.Describe(inpRaster)
    layersource = desc.catalogPath
    
    imageread=scipy.ndimage.imread(layersource)
    sobelimage=scipy.ndimage.sobel(imageread,0)
    
    outimage=PIL.Image.fromarray(sobelimage)
    Out=outimage.save('D:\Outputs\sobel.jpg') 
        
except arcpy.ExecuteError: 
    print "error"
    msgs = arcpy.GetMessages(2) 
    arcpy.AddError(msgs)  
    print msgs
except:
    print "error"
    tb = sys.exc_info()[2]
    tbinfo = traceback.format_tb(tb)[0]
    pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()[1])
    msgs = "ArcPy ERRORS:\n" + arcpy.GetMessages(2) + "\n"
    arcpy.AddError(pymsg)
    arcpy.AddError(msgs)
    print pymsg + "\n"
    print msgs





error
PYTHON ERRORS:
Traceback info:
  File "<string>", line 23, in <module>

Error Info:
"" does not exist

ArcPy ERRORS:
0 Kudos
MaherAL_ZUHAIRI
New Contributor
The error message because the function GetParameterAsText(0), so I used raster data instead , the error message has gone .
in other words, no error message in the code, but the problem I think is in the output function. the code is executed but the save function does not apply.
0 Kudos
DanPatterson_Retired
MVP Emeritus
try r'D:\Outputs\sobel.jpg'  for the filename
0 Kudos
MaherAL_ZUHAIRI
New Contributor
Same problem, can I convert the image into raster using RasterCopy Management. so may be that image will be saved.
if it is possible how can I do it.
0 Kudos