5 Replies Latest reply on Oct 27, 2014 11:57 AM by FionaG

    Color Model Conversion from RGB to HSV

    lilanelkenrot
      Hello,
      I have a Tiff-file containing several bands, three of them beeing RGB. I like to convert them to HSV color model.

      In 9.3 spatial analyst used to have the Color Model tools. I searched toolbox, resource centre, internet, but I coudn't find similar tools for ArcGIS 10. Did anyone find color model tools (that do not only apply to mosaic datasets) ?

      Apreciate every help!
      bye, lila
        • Re: Color Model Conversion from RGB to HSV
          lilanelkenrot
          In the meantime I implemented a python script to do the color conversion manually, but it is very very slow. How can I make things more efficient? I won't have a chance to convert my final raster.

          import arcpy
          from arcpy import sa
          import string
          import numpy
          import colorsys
          
          arcpy.env.workspace = r"U:\path" # internal drive
          
          inRast = r"U:\path\multiple_bands.tif"
          outRast = r"U:\path\hsv"
          
          Ymin = float(str(arcpy.GetRasterProperties_management(inRast, "BOTTOM")))
          Xmin = float(str(arcpy.GetRasterProperties_management(inRast, "LEFT")))
          Ymax = float(str(arcpy.GetRasterProperties_management(inRast, "TOP")))
          rows = float(str(arcpy.GetRasterProperties_management(inRast, "ROWCOUNT")))
          cols = float(str(arcpy.GetRasterProperties_management(inRast, "COLUMNCOUNT")))
          
          # create numpy arrays
          shape = rows, cols
          hueArray = numpy.empty(shape)
          satArray = numpy.empty(shape)
          valArray = numpy.empty(shape)
          
          x = 0
          while x < cols:
              y = 0
              while y < rows:
                  #Get the Cell values of the three bands
                  values = arcpy.GetCellValue_management(inRast, str(Xmin + 5 + 10*x) + " " + str(Ymax - 5 - 10*y), "1;2;3")
                  # save values in list
                  slist = string.split(str(values), "\\", 3)
                  b = float(slist[0])/255 # 1. Band Green equals blue in RGB
                  nlist = string.split(slist[1], "n", 2)
                  g = float(nlist[1])/255 # 2. Band Red equals green in RGB
                  nnlist = string.split(slist[2], "n", 2)
                  r = float(nnlist[1])/255 # 3. Band NIR equals red in RGB
                  # convert ot HSV
                  result = colorsys.rgb_to_hsv(r, g, b)
                  hueArray[y,x] = result[0]*360
                  satArray[y,x] = result[1]*100
                  valArray[y,x] = result[2]*100
                  
                  y = y + 1
              x = x + 1
          
          xymin = arcpy.Point(Xmin, Ymin)
          hueRast = arcpy.NumPyArrayToRaster(hueArray, xymin, 10, 10)
          satRast = arcpy.NumPyArrayToRaster(satArray, xymin, 10, 10)
          valRast = arcpy.NumPyArrayToRaster(valArray, xymin, 10, 10)
          
          satRast.save(outRast+"_sat.tif")
          valRast.save(outRast+"_val.tif")
          hueRast.save(outRast+"_hue.tif")
          
          • Re: Color Model Conversion from RGB to HSV
            lgzachos
            This may help others who come across this:

            The conversion tools for RGB to IHS and IHS to RGB are in the Toolbox : ERDAS Image Analysis Tools : Spectral Enhancement.

            I have no clue where the old RGB to HSV, etc. tools went.
            • Re: Color Model Conversion from RGB to HSV
              JSwain-esristaff
              You mean the color model conversion function within Mosaic Datasets?  To complete the described process, you could use the mosaic dataset to create the look and then export it, or just utilize the mosaic dataset.  That would be the recommended way to create the color model change.  The mosaic dataset should be fairly fast, if your script is causing performance problems.
              • Re: Color Model Conversion from RGB to HSV
                getlink
                really help a lot if you use color conversion tool. it is easy to convert RGB color mode to HSV color model. but i can't tell whether it is fit for ArcGIS. hope it is the right image sdk control for you.

                best luck
                Lily
                • Re: Color Model Conversion from RGB to HSV
                  FionaG

                  I finally found Color Model Conversion under the Image Analysis window in ArcMap (10.2.2). Highlight your image name at top of window ->Processing->fx->Right click on Identity Function -> Insert->choose Color Model Conversion from list.

                   

                  However it would not run on my 4 band Tiff. I don't know if this is because it is 4 bands (no option is given to select which bands to use for the color model) or because of its format. No useful error message, it just says the inputs are inappropriate.