# Application of IDL and ENVI Redevelopment in Hyperspectral Image Preprocessing

Long Xue

► To cite this version:

Long Xue. Application of IDL and ENVI Redevelopment in Hyperspectral Image Preprocessing. 4th Conference on Computer and Computing Technologies in Agriculture (CCTA), Oct 2010, Nanchang, China. pp.403-409, 10.1007/978-3-642-18369-0_47. hal-01564830

HAL Id: hal-01564830

https://inria.hal.science/hal-01564830

Submitted on 19 Jul 2017

HAL is a multi-disciplinary open access
archive for the deposit and dissemination of sci-
entific research documents, whether they are pub-
lished or not. The documents may come from
teaching and research institutions in France or
abroad, or from public or private research centers.

L'archive ouverte pluridisciplinaire HAL, est
destinée au dépôt et à la diffusion de documents
scientifiques de niveau recherche, publiés ou non,
émanant des établissements d'enseignement et de
recherche français ou étrangers, des laboratoires
publics ou privés.

<figure><img src="image_1.png" /></figure>

Distributed under a Creative Commons Attribution 4.0 International License
Application of IDL and ENVI redevelopment in
hyperspectral image preprocessing

薛龙 Long Xue1

1. School of Mechanical and Electronical Engineering, East China JiaoTong University,
Nanchang 330013, China
E-mail: ultimata@163.com

**Abstract.** In the last few years, hyperspectral imaging technique has had a bright future for application on nondestructive detection of agricultural products. However, in experiment, there are usually dozens or even hundreds of hyperspectral images. It needs to spend lots of time in preprocessing all the hyperspectral data. Software ENVI is a kind of image processing software, although the users can define their own algorithms and apply to the opened bands in ENVI or the bands and spectra operation of the images, it doesn't provide program to batch process. In this paper, the custom function "normalized" of Interactive Data Language (IDL) is applied to achieve batch processing on multiple hyperspectral images.

**Key words:** ENVI, redevelopment, hyperspectral image

# 1. Introduction

Software ENVI (The Environment for Visualizing Images) is image processing software. It is developed by the sciences of remote sensing using Interactive Data Language (IDL). It combines the latest spectral image processing and image analysis technology with an intuitive, user-friendly interface to help you get meaningful information from imagery. It can fast, conveniently, correctly extract information from geography and special image data. Therefore, it has been widely used in science research, environment protection, meteorology, agriculture, mineral and petroleum exploration. Since hyperspectral image combines the character of image and spectrum, so it is applied in agricultural product quality, food safety and nondestructive detection. At home, Hong Tiansheng et al. built prediction model of Chinese pear quality based on hyperspectral imaging technique and artificial neural network [1]. Zhao Jiewen et al. detected the subtle bruises on apple using hyperspectral image [2]. Liu Muhua et al. nondestructively detected soluble solids content and contamination on navel orange surface by hyperspectral laser-induced fluorescence imaging [3-4]. At abroad, M. S. Kim et al. detected fecal contamination on apple, cantaloupes using hyperspectral fluorescence imagery [5-8]. Juan Xing et al. detected surface defects on tomatoes by a hyperspectral imaging system [9]. In experiment, there are usually tens to hundreds of acquired hyperspectral images, and the images need to be
preprocessed. Although ENVI software offers interactive computing functions of spectral bands and spectrum, the same preprocessing of hundreds of images takes considerable time and is a very boring job.

This article uses IDL to write a batch program module based on ENVI, which can achieve the normalization preprocessing of the spectral data.

## 2. IDL and ENVI redevelopment

### 2.1 IDL introduction

IDL is the ideal, timesaving solution for data analysis, data visualization, and software application development. The users can quickly and easily use this software to convert the data to images. The converted images can be simple color, full color or three-dimensional images. As ENVI software provides the function interface of IDL, so the users can use the built-in IDL functional components, IDL users function, or a custom program. However, these functions must be kept in a directory of ENVI path list to be automatically compiled.

### 2.2 Spectral data preprocessing

Because the uneven distribution of light source intensity under the different wave bands and the presence of dark current noise of camera, so the images may contain more noises in some wave bands, therefore, the hyperspectral images must be normalized. Under the same experimental condition, the image of a stand white plate was acquired. The dark image was acquired by completely covering the lens with its cap. The normalization preprocessing is achieved according to equation (1):

$$I_{norm} = \frac{I_{sample} - I_{dark}}{I_{reference} - I_{dark}} \qquad (1)$$

Where: $I_{norm}$ —the pixel value of the image after normalized preprocessing;

$I_{sample}$ —the pixel value of a sample image;

$I_{reference}$ —the pixel value of standard white plate;

$I_{dark}$ —the pixel value of the dark image.
## 2.3 ENVI redevelopment

The most common method of ENVI software redevelopment is using IDL to develop small application program modules, and call these modules. Meantime, these modules must be stored in the directory "X:\RS\IDLXX\products\enviXX\save_add" to be compiled automatically. In this article, the hyperspectral files to be processed were saved in the directory "X:\original", and a total of n hyperspectral files were named according to numerical order (such as DH1/raw, DH2/raw, ..., DHn/raw). In the folder, The standard white plate hyperspectral image (white/raw) and the dark hyperspectral image (black/raw) were saved in the same folder. After preprocessing, the hyperspectral files were stored in the directory "x: \ normalized \ folder", the program code is as follows:

```idl
; Building the patch processing program module of
; hyperspectral images "normalized". The function is to
; normalize the original images.

pro normalized

; Setting the path of hyperspectral files to be
; processed.

inpath=' X:\original\'

; Setting the path of hyperspectral files having been
; processed.

outpath=' X:\normalized\'

; Defining the array "filename" which was used to
; store the file name of dark image and standard white
; plate image.

filename = ['black/raw', 'white/raw']

; read the hyperspectral files, L represents the data
; is numerical type.

for j=1L,nL do begin

; Converting data from numerical type to character
; type

num=string(format=' (i0) ',j)

; Saving the path and file name of a specific
```
hyperspectral file with "in_name"

in_name0=inpath+num+'.'+raw'

; Printing the file name in IDL screen to express the
processing course

print,in_name0

; Opening the file, option "no_realize" represents
that the file will not be opened in available band
list, and "fid" is the number of the file.

envi_open_file, in_name0,/no_realize, r_fid=fid

; Opening the dark and standard white plate images.

in_name1=inpath+filename[0]

in_name2=inpath+filename[1]

envi_open_file, in_name1,/no_realize,r_fid=fid2

envi_open_file, in_name2,/no_realize,r_fid=fid3

; Accessing file's information, "ns" represents the
sample number of the file, "nl" represents the number
of lines, "nb" represent the number of bands,
"xstart" and "ystart" represents the pixel
coordinates of the top left corner in the image and
the default value is (1,1).

envi_file_query, fid, interleave=interleave,ns=ns,
nl=nl, nb=nb,dims=dims, data_type=_datatype,
xstart=_xstart,
ystart=_ystart,SPEC_NAMES=SPEC_NAMES

; " dims " is the spectral range to be processed. " Ssn "
represents the first file, and " esn " represents the
last file. " sln " represents the first line of the
file, and " eln " is the last line.

pos=lindgen nb)

dims=[-11,ssn,esn,sln,eln]
envi_file_query, fid2, interleave=interleave2

envi_file_query, fid3, interleave=interleave3

; Setting the command blocks.

tile_id=envi_init_tile(fid, pos num tiles num tiles
interleave=interleave>1, xs=dim s [1], xe=dim s [2], ys=di
ms [3], ye=dim s [4])

tile_id2=envi_init_tile(fid2, pos, num tiles=num tile
s,
interleave=interleave>1, xs=dim s [1], xe=dim s [2], ys=di
ms [3], ye=dim s [4])

tile_id3=envi_init_tile(fid3, pos, num tiles num tile
s,
interleave=interleave>1, xs=dim s [1], xe=dim s [2], ys=di
ms [3], ye=dim s [4])

; Processing each block data, and saving the file in
the directory "x:\normalized\"

openw, _unit, outpath+num+'.'raw', /get_lun

for i=0L, num tiles-1 do begin

data = envi_get_tile浴( tile_id, i)

data2 = envi_get_tile( tile_id2, i)

data3 = envi_get_tile( tile_id3, i)

data4=(float(data)-float(data2))/(float(data3)-
float(data2))

writeu, _unit, data4

endfor

free_lun, _unit

; Building the head file.

envi_setup_head, fname=outpath+aa, ns=dim s [2]-
```matlab
dims[1]+1,nl=dims[4]- dims[1]+1, nb=nb, data_type=4,
offset=0,
interleave=interleave, xstart=_xstart+ dims[1],
ystart=_ystart+ dims[3], descrip=' Normalized file',
/write
```

```matlab
; Releasing the command block.
```

```
envi_tile_done, tile_id
```

```
envi_tile_done, tile_id2
```

```
envi_tile_done, tile_id3
```

```
envi_file_mng, id=fid, /remove
```

```
envi_file_mng, id=fid2, /remove
```

```
envi_file_mng, id=fid3, /remove
```

```matlab
; Printing the number of a file which has been
processed.
```

```
print, num
```

```
close, /all, /force
```

```
endfor
```

```
envi_batch_exit
```

```
end
```

The image of pear at 680nm before preprocessing is shown in Figure 1. From figure 1, the obvious strip in the image is found easily. Figure 2 shows the image of pear at 680nm after preprocessing, the quality of image is improved greatly.
<figure><img src="image_2.png" /><figcaption>Figure.1 Image of pear at 680nm before preprocessing</figcaption></figure>

<figure><img src="image_3.png" /><figcaption>Figure.2 Image of pear at 680nm after preprocessing</figcaption></figure>

Figure 3 show the average visible and near-infrared spectra in the 500 to 950nm region of the pear, (a) before preprocessing, (b) after preprocessing.
<figure><img src="image_4.png" /><figcaption>(a) Before preprocessing</figcaption></figure>

<figure><img src="image_5.png" /><figcaption>(b) After preprocessing</figcaption></figure>

Figure.3 The average visible and near-infrared spectra in the 500 to 950nm region of the pear

## 3. Conclusion

By using IDL language and ENVI redevelopment, an extensible remote sensing system with perfect functions can be developed. Nowadays, this system is further expansion because more and more research achievements are integrated in it by scientific researchers. The strong abilities of IDL language and ENV redevelopment make the scientific researchers can release from boring programming work to invest more time and effort to actual research.
Reference

[1]Hong Tiansheng, Qiao Jun, Ning Wang, et al. "Non-destructive inspection of Chinese pear quality based on hyperspectral imaging technique". Transactions of the CSAE, 2007, 23 (2)P.151-155.

[2] Zhao Jiewen, Liu Jianhua, Chen Quansheng, Saritporn Vittayapadung. "Detecting Subtle Bruises on Fruits with Hyperspectral Imaging " Transactions of the Chinese Society for Agricultural Machinery, 2008 (31)1,P.106-109.

[3]Guo Enyou, Liu Muhua, Zhao Jiewen, Chen Quansheng. "Nondestructive Detection of Sugar Content on Navel Orange with Hyperspectral Imaging ". Transactions of the Chinese Society for Agricultural Machinery,2008,39(05)P.91-93,103.

[4]Xue Long, Li Jing, Liu Muhua. "Detecting Pesticide Residue on Navel Orange Surface by Using Hyperspectral Imaging". Acta Optica Sinica, 2008, 28(12)P.2277~2280

[5]Kim Moon S, Alan M. Lefcourt, Chen Yud-Ren. "Ns-scale time-resolved laser induced fluorescence imaging for detection of fecal contamination on apples". SPIE, 2004, P.5587: 190~197

[6]Vargas AM, Kim MS, Tao Y, Lefcourt A, Chen Y-R. "Safety Inspection of Cantaloupes and Strawberries Using Multispectral Fluorescence Imaging Techniques". ASAE Paper 2006, No.043056.St.Joseph, Mich.:ASAE.

[7]Moon S.Kim, Alan M. Lefcourt, Yud-Red Chen. "Automated detection of fecal contamination of apples based on multispectral fluorescence image fusion". J. Food Engineering, 2005, 71, P. 85~91.

[8]Kang-Jin Lee, Sukwon Kang, Moon S. Kim. "Hyperspectral imaging for detecting defect on apples". ASABE Paper No. 053075. St. Joseph, Mich.: ASABE, 2005.

[9]Xing J, Ngadi M, Wang N. "Wavelength Selection for Surface Defects Detection on Tomatoes by Means of a Hyperspectral Imaging System". ASAE Paper 2006, No.063018 St.Joseph, Mich.:ASAE.