I am trying to make a workflow on my raster image analysis in Python window.
One of the steps is to convert RGB to HSV color mode, which is done in Image Analysis Window. This raster function creates a temporary layer. I was wondering if I can combine this step using script in Python. I don't know how to call this raster function or is it even possible to call it because it is not a ArcTool.
Thanks.
Solved! Go to Solution.
Hi Jing,
Here is your code.
arcpy.MakeRasterLayer_management(r'<image file path>',"imagelayer")
arcpy.EditRasterFunction_management("imagelayer", function_chain_definition=r"f:\temp\RGB2HSV.rft.xml")
In 10.4, you will need to save a color model conversion function template first using the function template editor. The function template file is a *.rft.xml file as shown above.
If you don't know how to create the function template using the editor. Here is the doc link
Accessing the Raster Function Template Editor—Help | ArcGIS Desktop
My understanding is you just need the layer, then the above code should suffice.
Not a tool? not a chance (that I can find). But there are RGB to various color models that can be implemented in python/numpy should you want to convert to a numpy array. There is the whole Scipy slate (including some specific image focussed libraries) should you want to go the script route, which you can obviously incorporate in ArcMap and PRO tools
Thanks. I am pretty new to this type of analysis. I looked it up and color mode conversion was in ArcTool of previous version (ArcGIS 9). But not they moved it to Image Analysis as a raster function. I know there might be a lot of ways to do this. If I am understanding this correctly, I can convert the raster image to a numpy array and use matplotlib.color? And then convert it back to raster image?
for a color conversion I suppose, but http://scikit-image.org/ is what I was referring to.
Arcpy, python, numpy, scipy are all part of pro, scikit-image can be installed within the conda distribution with PRO so you can decide what to do with images. If the image analyst doesn't provide tools in arctoolbox, then you are limited in that you can't acquire access to tool functionality. If methods and properties aren't exposed in arcpy... ditto. But esri provides the capability to bring in whatever you want from the scientific distributions and use them (even R (r) )
PS... the matplotlib to which you refer
https://matplotlib.org/api/colors_api.html#matplotlib.colors.rgb_to_hsv
and python docs
Jing
You don't need to convert the raster. RGB to HSV is a raster function that you can call from Python.
One of our engineers will provide a more detailed response soon.
Cody B.
Great. Thanks. I am looking forward to it!
Hi Jing,
Here is your code.
arcpy.MakeRasterLayer_management(r'<image file path>',"imagelayer")
arcpy.EditRasterFunction_management("imagelayer", function_chain_definition=r"f:\temp\RGB2HSV.rft.xml")
In 10.4, you will need to save a color model conversion function template first using the function template editor. The function template file is a *.rft.xml file as shown above.
If you don't know how to create the function template using the editor. Here is the doc link
Accessing the Raster Function Template Editor—Help | ArcGIS Desktop
My understanding is you just need the layer, then the above code should suffice.
Many thanks. That solved my problem.
Jing
Thanks Jie
Cody