Directory of series articles
For example: Chapter 1
Article directory
- Table of Contents of Series Articles
- Preface
- 1. What is pandas?
-
-
- 1.ROI mask function
- 2. Image mosaic function
- 3. Calculate the keywords required for the mosaic
- 4. Perform batch mosaic, cropping, and masking
-
- Summarize
Foreword
For example: With the continuous development of artificial intelligence, machine learning technology is becoming more and more important. Many people have started learning machine learning. This article introduces the basic content of machine learning.
1. What is pandas?
1.ROI mask function
code show as below:
pro process_mask, evf_id,fid,o_fn=o_fn ;Mask operation on encounter image based on EVE file The method index comes from ;The parameter evf_id is the vector file id number, fid is the remote sensing image fid number ;Keyword o_fn is the file name of the mask result image ;First create ROI file based on image size ;envi_file_query file attribute query function based on fid envi _file_query,fid,ns=ns,nl=nl,nb=nb, dims=dims ;Create ROI mask roi_id_mask=envi_create roi(ns=ns, nl=nl, name='mask', color=l) ;Get the coordinate values of each node in EVE to create ROI polygons envi_evf_info,evf_id,num_recs=nrecs for i=0,nrecs-1 do begin record=envi_evf_read_record(evf_id,i) ;array transpose xmap=transpose(record[0,*]) ymap=transpose(record[1*]) ;envi_convert_file_coordinates: ;routine, without return value, conversion between matrix coordinates and spatial coordinates of certain points on the graph (in the case of spatial information \t;Down). Example: envi_convert_file_coordinates, fid, xf, yf, xmap, ymap, /to_map ;(xf, yf are the coordinates of the matrix, xmap, ymap are the spatial coordinates) envi_convert_file_coordinates, fid,xf,yf,xmap,ymap ;Define ROI envi_define_roi,roi_id_mask,/polygon,xpts=xf,ypts=yf endfor ;Convert ROI to image, set the pixel value of the corresponding category of ROI to 1, which is Mask envi_doit,'envi_roi_to_image_doit', fid=fid, r_fid=fid_mask,$ roi_ids=roi_id_mask,out_name='Mask', class_values=1 ;Perform mask operation envi_doit, 'envi_mask_apply_doit', fid=fid, m_fid=fid_mask,$ m_pos=0, out_name=o_fn, dims=dims, pos=indgen(nb), value=0 ;Delete intermediate files envi_file_mng,id=fid, /remove, /delete envi_file_mng,id=fid_mask, /remove, /delete
2. Image mosaic function
code show as below:
function process_mosaic,fns ; Perform spatial mosaic processing based on the file name array, and the return result is the fid number of the mosaic data. ;The parameter fns is an array of file names fnums=n_elements(fns) dimss=lonarr(5,fnums);Spatial range storage array fids=lonarr(fnums) ;file fid number storage array ;Open each scene data and obtain its fid number and spatial range for i=0,fnums-1 do begin envi_open_file,fns[i],r_fid-fid envi_file_query, fid, nb=nb, dims=dims, data_type=data_type fids[i]=fid dimss[*,i]=dims;space subset endfor ;Band range storage array poss=intarr(nb,fnums) for i=0,fnums-1 do poss[*,i]=indgen(nb) ;pixel resolution map_info=envi_get_map_info(fid=fid) pixel_size=map_info.ps ;Call georef_mosaic_setup to calculate the keywords xsize, ysize, x0, y0 required for mosaic georef_mosaic_setup, fids=fids, dims=dimss, map_info=map_info,$ out_ps=pixel_size,xsize=xsize,ysize=ysize,x0=x0,y0-y0 ; Mosaic operation see_through_val=bytarr(fnums) use_see_through=see_through_val + 1 envi_doit,'mosaic_doit',fid=fids,dims=dimss,pos=poss,$ r_fid=fid_mosaic, out_name='mosaiced_data',/georef, $ map_info=map_info, see_through_val=see_through_val, $ use_see_through=use_see_through, background=0,out_dt=data_type, $ pixel_size=pixel_size,xsize=xsize,ysize=ysize,x0=x0,y0=y0 return,fid_mosaic end
3. Calculate the keywords required for mosaic
code show as below:
;********************************************** *** ; georef_mosaic_setup program provided by IDL official website ; Used to calculate the keywords xsize, ysize, x0, y0 required for inlaying PRO GEOREF_MOSAIC_SETUP, fids = fids, dims = dims, out_ps = out_ps, $ xsize = xsize, ysize = ysize, x0 = x0, y0 = y0, map_info = map_info COMPILE_OPT strictarr, hidden ; Some basic error checking IF KEYWORD_SET(dims) THEN $ IF N_ELEMENTS(fids) NE N_ELEMENTS(dims[0, *]) THEN dims = 0 ; IF N_ELEMENTS(fids) LT 2 THEN BEGIN xsize = -1 ysize = -1 x0 = -1 y0 = -1 RETURN ENDIF ; If no DIMS passed in nfiles = N_ELEMENTS(fids) IF (KEYWORD_SET(dims) EQ 0) THEN BEGIN dims = FLTARR(5, nfiles) FOR i = 0, nfiles - 1 DO BEGIN ENVI_FILE_QUERY, fids[i], dims = tmp_dims dims[*, i] = tmp_dims ENDFOR ENDIF ; Compute the size of the output mosaic (xsize and ysize) ; Store the map coords of the UL corner of each image since you'll need it later UL_corners_X = DBLARR(nfiles) UL_corners_Y = DBLARR(nfiles) east = -1e34 west = 1e34 north = -1e34 south = 1e34 FOR i = 0, nfiles - 1 DO BEGIN pts = [[dims[1, i], dims[3, i]], $ ; UL [dims[2, i], dims[3, i]], $ ; UR [dims[1, i], dims[4, i]], $ ; LL [dims[2, i], dims[4, i]]] ; LR ENVI_CONVERT_FILE_COORDINATES, fids[i], pts[0, *], pts[1, *], xmap, ymap, /to_map UL_corners_X[i] = xmap[0] UL_corners_Y[i] = ymap[0] east = east > MAX(xmap) west = west < MIN(xmap) north = north > MAX(ymap) south = south < MIN(ymap) ENDFOR xsize=east-west ysize = north - south xsize_pix = ROUND(xsize/out_ps[0]) ysize_pix = ROUND(ysize/out_ps[1]) ; to make things easy, create a temp image that's got a header ; that's the same as the output mosaic image proj = ENVI_GET_PROJECTION(fid = fids[0]) map_info = ENVI_MAP_INFO_CREATE(proj = proj, mc = [0, 0, west, north], ps = out_ps) temp = BYTARR(10,10) ENVI_ENTER_DATA, temp, map_info = map_info, /no_realize, r_fid = tmp_fid ; find the x and y offsets for the images x0 = LONARR(nfiles) y0 = LONARR(nfiles) FOR i = 0, nfiles - 1 DO BEGIN ENVI_CONVERT_FILE_COORDINATES, tmp_fid, xpix, ypix, UL_corners_X[i], UL_corners_Y[i] x0[i] = ROUND(xpix) y0[i] = ROUND(ypix) ENDFOR ; delete the tmp file ENVI_FILE_MNG, id = tmp_fid, /remove, /no_warning END
4. Perform batch mosaic, cropping, and masking
The code is as follows (example):
pro process_mosaic_clip_mask ;envi function is found in the envi help document. ;Clip daily data and give vector data t1 = systime(1) ;Program start time ; *************** Open vector data**************** ; Set the path where the data is located work_dir = dialog_pickfile(title = 'Select the path where the file is located',/directory) cd, work_dir ; Open boundary data fn_boundary = dialog_pickfile(filter = '*.evf', title = 'Select vector data') evf_id = envi_evf_open(fn_boundary) ;******************Spatial range of statistical vector data****************** envi_evf_info, evf_id, num_recs = nrecs, projection = proj corner = dblarr(4, nrecs) ;The four columns correspond to the maximum and minimum values of the abscissa and the maximum and minimum values of the ordinate for i=0, nrecs-1 do begin ; Get the spatial range of each record record = envi_evf_read_record(evf_id, i) corners[0,i] = min(record[0,*]);minimum value of abscissa corners[1,i] = min(record[0,*]);maximum value of abscissa corners[2,i] = min(record[1,*]);minimum value of ordinate corners[3,i] = min(record[1,*]);maximum value of ordinate endfor ;Calculate the minimum and maximum values of the horizontal and vertical coordinates of all vector records UL_xmap = min(corners[0,*]) UL_ymap = max(corners[3,*]) LR_xmap = min(corners[1,*]) LR_ymap = max(corners[2,*]) ; ******************Loop daily to perform preprocessing such as mosaic, cropping and masking************************ ************* for i_day = 1, 365 do begin ; Get all remote sensing data file names for the current day ft = 'Day' + string(i_day,format = 'i3.3') fns = file_search(ft + '*.{hdr,HDR}',count = fnums) ENVI_fns = strrr(fnums) for i=0, fnums-1 do begin ENVI_fns[i] = strmid(fns[i], 0,strlen(fns[i])-4) endfor ; Complete the mosaic of all remote sensing data for the day fid_mosaiced = process_mosaic(ENVI_fns) envi_file_query, fid_mosaiced,ns = ns, nl = nl, nb = nb ; Get the cropping range envi_convert_file_coordinates, fid_mosaiced, xf_UL, yf_UL, UL_xmap, UL_ymp envi_convert_file_coordinates, fid_mosaiced, xf_LR, yf_LR, LR_xmap, LR_ymp dims = [-1,floor(xf_UL),ceil(xf_LR),floor(yf_UL),ceil(yf_LR)] ; Perform cropping operation pos=indgen(nb) envi_doit,'resize_doit', fid=fid_mosaiced,r_fid=fid_cliped,$ dims=dims, pos=pos, rfact=[1, 1], out_name='cliped_data' envi_file_query,fid_cliped,ns=ns,nl=nl,data_type=data_type map_info=envi_get_map_info(fid=fid_cliped) ; Delete intermediate files envi_file_mng, id=fid_mosaiced, /remove, /delete ; Perform masking operation process_mask,evf_id,fid_cliped,o_fn='Result_i' + ft endfor t2 = systime(1); program end time print, 'Time consuming (minutes):', (t2-t1)/60 end