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.



5391 Rate this article:
No rating

How to convert a TIFF to a classification image programmatically

This Help Article provides an example of how to open a single-band, grayscale TIFF and convert it into an 'ENVI Classification' image programmatically. This is sometimes necessary since classified images stored in TIFF do not always import as a classification image.

--------------------------------------------

pro tiff_2_classification

;select file and query it for file information
fname = envi_pickfile(title = 'Select single band file to convert to classification')
	if (name eq '') then return  
envi_open_file, fname, r_fid=fid
envi_file_query, fid, ns=ns, nl=nl, nb=nb, dims=dims, $
	interleave=interleave, data_type=data_type

;calculate the min/max of the band in order to generate 
;the correct number of classes based on DN
envi_doit, 'envi_stats_doit', fid=fid, dims=dims, pos=0, $
	dmin=dmin, dmax=dmax, comp_flag=1

;generate the number of classes, class names, and class colors
num_classes = dmax-dmin + 1
classes = strarr(num_classes - 1)
for i=0, n_elements(classes) - 1 do begin
	classes[i] = 'Class_'+ strtrim(string(i), 1)
end

class_names = ['Unclassified', classes]
lookup = envi_color_rgb([0,indgen(n_elements(classes))+2])

;generate the ENVI header with the new information
file_type = envi_file_type('ENVI Classification')
envi_setup_head, fname=fname, ns=ns, nl=nl, nb=nb, interleave=interleave, $
	data_type=data_type, file_type=file_type, class_names=class_names, $
	lookup=lookup, num_classes=num_classes, /write

;remove the open file so it can be reopened
envi_file_mng, id=fid, /remove
envi_open_file, fname

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 »