+ Reply to Thread
Results 1 to 5 of 5

Thread: Color Model Conversion from RGB to HSV

  1. #1
    Caro Foehn
    Join Date
    Nov 2010
    Posts
    3
    Points
    0
    Answers Provided
    0


    0

    Arrow Color Model Conversion from RGB to HSV

    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

  2. #2
    Caro Foehn
    Join Date
    Nov 2010
    Posts
    3
    Points
    0
    Answers Provided
    0


    0

    Thumbs down Re: Color Model Conversion from RGB to HSV

    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.

    Code:
    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")

  3. #3
    Louis Zachos
    Join Date
    Sep 2011
    Posts
    3
    Points
    0
    Answers Provided
    0


    0

    Default Re: Color Model Conversion from RGB to HSV

    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.

  4. #4
    Jeff Swain

    Join Date
    Nov 2009
    Posts
    749
    Points
    184
    Answers Provided
    21


    0

    Default Re: Color Model Conversion from RGB to HSV

    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.
    Esri Education Specialist
    Esri Certified ArcGIS Desktop Professional
    Training Services
    Esri Training | ArcGIS Ideas

  5. #5
    dsf fdsdf
    Join Date
    Feb 2014
    Posts
    1
    Points
    0
    Answers Provided
    0


    0

    Default Re: Color Model Conversion from RGB to HSV

    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

+ Reply to Thread

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts