X

Help Articles are product support tips and information straight from the NV5 Geospatial Technical Support team developed to help you use our products to their fullest potential.



4370 Rate this article:
2.0

Band math function to reclass an RGB image

Sometimes classification images are saved in a data format that converts the data from a single band color class file to a 3-band RGB image (for example, saving a classification image to TIFF from the ENVI display). You can restore the classes by setting the various RGB ranges to a specific class value using Band Math. This Help Article shows an example of a simple band math function that can be used to 'reclass' an RGB image.
 
The below code is an example band math function that will assign various RGB combinations to specific classes. The example was used on a classification image saved as an RGB TIFF, which resulted in 3 bands ranging from 0 to 256. The band math function should be altered to represent the number of RGB combinations (classes) that exist in the image. The result will be a gray-scale image with a data type of byte. You can then change the file type in the ENVI header to 'ENVI Classification' and assign colors to the data values to recreate the classification image.

;*************************************************************************
function reclass_rgb, b1, b2, b3, c1, c2, c3, c4, c5, c6, c7
;
; Example function for use in Band Math.
;
;;
; find which pixels in each band  fall into each class
;
class1 = WHERE(b1 eq 0 and b2 eq 0 and b3 eq 0, count1)
class2 = WHERE(b1 eq 255 and b2 eq 0 and b3 eq 0, count2)
class3 = WHERE(b1 eq 0 and b2 eq 255 and b3 eq 0, count3)
class4 = WHERE(b1 eq 0 and b2 eq 0 and b3 eq 255, count4)
class5 = WHERE(b1 eq 255 and b2 eq 255 and b3 eq 0, count5)
class6 = WHERE(b1 eq 0 and b2 eq 255 and b3 eq 255, count6)
class7 = WHERE(b1 eq 255 and b2 eq 0 b3 eq 255, count7)

;reclassify to 7 classes
classified = BYTE(b1)
IF count1 NE 0 THEN classified(class1) = 0B
IF count2 NE 0 THEN classified(class2) = 1B
IF count3 NE 0 THEN classified(class3) = 2B
IF count4 NE 0 THEN classified(class4) = 3B
IF count5 NE 0 THEN classified(class5) = 4B
IF count6 NE 0 THEN classified(class6) = 5B
IF count7 NE 0 THEN classified(class7) = 6B

;
; return the classified image
;
RETURN, classified

end

Review on 12/31/2013 MM

Please login or register to post comments.
Featured

End-of-Life Policy Enforcement for ENVI 5.3 / IDL 8.5 and Earlier Versions

5/6/2024

April 1, 2024 Dear ENVI/IDL Customer,  We are reaching out to notify you of our supported... more »

How to Upgrade licenses to ENVI 6.x / IDL 9.x

12/5/2023

What is the new Upgrade function? Starting with ENVI 6.0 and IDL 9.0, we have implemented an... more »

What to do if the 'License Administrator - License Server' for the Next-Generation License Server does not start?

6/13/2023

Background: With the release of ENVI 5.7 & IDL 8.9 and the corresponding Next-Generation licensing... more »

Next-Generation Licensing FAQ

4/28/2023

  NV5 Geospatial has adopted a new licensing technology for all future releases of our ENVI, IDL... more »

The IDL Virtual Machine

6/6/2013

What is the IDL Virtual Machine? An IDL Virtual Machine is a runtime version of IDL that can... more »