I need your advice on a new RGB function chain in MD, which will follow the following rules:
1. Input: images already added in MD (6 bands per image, 16 bit pixel depth per image & MD);
2. Create RGB as 16 bit, where R is from band 3, B is from band 1, but G is calculated with the formula: band 2 * 0.7 + band 4 * 0.1 + band 6 * 0.2 (used to identify types of insects diseases in farming and forest lands);
3. Output:RGB as 8 bit (ready for other tasks such as color balancing to match a 8-bit target, if necessary)
Thanks in advance
If you only have 4-band imagery like GEOEYE, G can be replaced with the formula like band 2 * 0.7 + band 4 * 0.3
I wonder if it is really necessary to use a Python function for your case (although the variability of the number of bands available worries me). You can start with simple configuration and use Band Arithmetic function—Help | ArcGIS Desktop to calculate the band assign to G.
In order for me to easily follow, may you share a customizable function chain with similar rules? If possible, please attach a snapshot.
As you know, 'Sultan's Formula' (very much closer to what we look for, i.e., RGB) and 'User Defined' (only one band to be created) in the drop down list under Band Arithmetric are available. But, it looks that 'Sultan's Formula' method is not customizable. In fact, the original intention is how to find out an easy way to customize (not create) an image processing and analysis function from any existing functions.
As recommended, the good slides on creation of a NEW raster function can be accessible here: how to write image processing algorithms using the Python Raster Function). It may be right time to learn how to properly call ERDAS Spatial Modeler, scikit, and OpenCV in MD, ArcGIS. In fact, very often for us to directly call ArcPy, scikit and OpenCV within ERDAS Spatial Modeler (via Python Script operator) without any significant coding effort.
Many thanks and regards,
A couple of years ago I did see a presentation at the DevSummit about this and it is a very powerful thing. However, before you start using it, always validate if configuration can do the job. I blogged about using some configuration of Raster Chain Functions here:https://community.esri.com/people/xander_bakker/blog/2016/07/18/using-mosaic-datasets-and-raster-cha... but I haven't done anything with a Python raster function.
Let me tag some experts and see if they have some time to shed their light on this.
You could use the Python raster function to do this, but I don't think it is necessary. This can probably be done using out of the box functions. Try building a fx chain that looks something like this in the function editor.
You can extract the two bands you need the raw values from then for band G you can use band arithmetic with a user defined formula. In your case it will look something like this:
At this point you can use composite band to put them all back together then use the stretch function to convert it back to 8 bit.
If you still want to head down the Python raster fucntion path I can help you with that as well. It will just require a bit of coding.
Hope this helps.
Jamie, thanks a lot.
It works as expected.
Certainly, I would like to take this opportunity to learn from you how effectively to utilize a out-of-box Python Raster Function in MD, if you can demonstrate the codes with snapshots.
Again, thanks for your quick assistance.
Good to hear. We have a github repo with a bunch of samples in it. They are here. The sample range from basic NDVI to more complex raster functions. That would be a good place to start. Some of them have package dependencies that might not be installed with ArcGIS. Although most of them do come installed. The setup.py from here will install everything required by our repo. If you want to use a module that is not in there you will have to install it yourself. I would recommend pip install. It is probably the easiest way.
Once you have written a Python function is can be inserted into a function chain as a first class item just like out of the box functions. Inserting a Python function in 10.x can be done by right clicking on an item in a function chain then selecting insert python raster function. Point to the .py file and you should be good to go. This can also be done in Pro. Just a slightly different workflow. There is a wiki for this repo that should explain all the details. Let me know if you have any questions along the way. I'd be happy to help.
Really helpful. Worth to deeply dig into raster functions in MD, which can be used to solve more complex raster and imagery intelligence challenges in operation, even as an innovation platform.
Can you please help check if the contents is accessible to you? It looks invisible, which shows blank under the title...
Yes. It is broken for me too. Not sure what is wrong. I'll have to take a look when i get back from thanksgiving on Monday. Sorry about that. That section just describes some of the do's and don't of writing raster functions that are optimized for performance.
For example. Avoiding looping through pixel arrays when possible. It can be done but it will slow down performance. It is better to use numpy/scipy and other array packages to process image instead.