How do I call the raster function "Color model conversion" in Raster Image Analysis in Python Window in ArcGIS 10.4?

1408
9
Jump to solution
01-31-2018 12:00 PM
JingZhang3
New Contributor

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.

0 Kudos
1 Solution

Accepted Solutions
JieZhang
Esri Contributor

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. 

View solution in original post

9 Replies
DanPatterson_Retired
MVP Emeritus

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

0 Kudos
JingZhang3
New Contributor

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? 

0 Kudos
DanPatterson_Retired
MVP Emeritus

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) )

DanPatterson_Retired
MVP Emeritus
0 Kudos
CodyBenkelman
Esri Regular Contributor

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. 

JingZhang3
New Contributor

Great. Thanks. I am looking forward to it!

0 Kudos
JieZhang
Esri Contributor

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. 

JingZhang3
New Contributor

Many thanks. That solved my problem.

Jing

0 Kudos
CodyBenkelman
Esri Regular Contributor

Thanks Jie

Cody

0 Kudos