I want to quickly classify a selection of points within an image using k-means. The problem is that 'class_doit' returns an image consisting of a single point when supplied with an roi consisting of multiple points when the following code is used:
; Create roi
ENVI_DELETE_ROIS, /all
xpts = lindgen(100)
ypts = lindgen(100)
envi_define_roi, roi_id, /point, xpts=xpts, ypts=ypts
; Open File
target = 'D:\Spot\SPOT 5\site\pan_site'
envi_open_file, target, r_fid = fid
envi_file_query, fid, dims=dims, ns = ns, nl=nl
; Create Roi
roiId=envi_create_roi(ns=ns, nl=nl, color=4, name='root')
xpts = indgen(100)
ypts = indgen(100)
envi_define_roi, roiId, /point, xpts=xpts, ypts=ypts
dims = [envi_get_roi_dims_ptr(roiId),0,0,0,0]
; Run k-means on image (returns single point image)
envi_doit, 'class_doit', dims = dims, fid = fid, method = 7, num_classes = 2, iterations = 2, $
change_thresh = 0.01, pos = [0], r_fid = splitFid, /in_memory
; Returns stats of all points in ROI
envi_stats_doit, fid=fid, dims=dims, pos= [0], comp_flag=0, $
report_flag=0, mean=mean, stdv=stdv, dmin=dmin, dmax=dmax
print, dmin, dmax, mean, stdv
end
Is there a way to quickly apply the k-means algorithm to points of an image programmatically? I've tried using a mask of the entire image but I'm hoping to avoid both the time and memory required to build the mask.
|