def process(path_in): """Open/Process/Write the image in the given path. Args: path_in(str) """ arr_in = IO.read(path_in) arr_out = arr_in path_out = path_in IO.write(arr_out, path_out) logging.info('%s processed [Ok]' % path_in)
#!/usr/bin/env python import numpy as np import skfuzzy as fuzz from geotiff.io import IO # load original image DIR = 'C:/Data/Tewkesbury-LiDAR' img = IO.read(DIR + '/stack-lidar.data/Sigma0_HH_slv1_25Jul2007.img') # pixel intensities I = img.reshape((1, -1)) # params n_centers = 2 fuzziness_degree = 2 error = 0.005 maxiter = 1000 # fuzz c-means clustering centers, u, u0, d, jm, n_iters, fpc = fuzz.cluster.cmeans(I, c=n_centers, m=fuzziness_degree, error=error, maxiter=maxiter, init=None) img_clustered = np.argmax(u, axis=0).astype(float) # display clusters img_clustered.shape = img.shape IO.write(img_clustered, DIR + '/fuzzy-clustered.tif')
#!/usr/bin/env python import matplotlib.pyplot as plt from geotiff.io import IO # load original image input_file = '/'.join(('C:', 'Data', 'Tewkesbury-LiDAR', 'subset.data', 'Sigma0_HH_slv1_25Jul2007.img')) img = IO.read(input_file) # histogram of the image plt.hist(img.flatten(), bins=10, range=[0, 10]) plt.show()
#!/usr/bin/env python import numpy as np from skimage.filters import threshold_otsu from geotiff.io import IO # load two images DIR = 'C:/Data/Tewkesbury-LiDAR' img_pre = IO.read(DIR + '/subset.data/Sigma0_HH_slv2_22Jul2008.img') img_post = IO.read(DIR + '/subset.data/Sigma0_HH_slv1_25Jul2007.img') # otsu thresholding of the two images threshold_pre = threshold_otsu(img_pre) img_thresholded_pre = img_pre < threshold_pre print 'Threshold for image pre:', threshold_pre IO.write(img_thresholded_pre, DIR + '/thresholded-pre.tif') threshold_post = threshold_otsu(img_post) img_thresholded_post = img_post < threshold_post print 'Threshold for image post:', threshold_post IO.write(img_thresholded_post, DIR + '/thresholded-post.tif') # difference between the two thresholded images img_difference = np.subtract(img_thresholded_post, img_thresholded_pre, dtype=np.float) IO.write(img_difference, DIR + '/difference.tif')
#!/usr/bin/env python """Split-based thresholding of a GeoTIFF image.""" from skimage.filters import threshold_otsu from geotiff.io import IO # constants SPLIT_SIZE = 100 PATH = 'C:/Data' IN_PATH = PATH + '/namibia-flipped.data/Sigma0_HH.img' OUT_PATH = PATH + '/namibia-splits/serbia-split-(%s,%s).tiff' # load original image img = IO.read(IN_PATH) img_xsize = img.shape[1] img_ysize = img.shape[0] # extract splits iteratively & their thresholds local_thresholds = [] y_offset = 0 while y_offset < img_ysize: x_offset = 0 while x_offset < img_xsize: # estimate the otsu threshold for each split split_xsize = ( SPLIT_SIZE if x_offset + SPLIT_SIZE < img_xsize else img_xsize - x_offset ) split_ysize = ( SPLIT_SIZE if y_offset + SPLIT_SIZE < img_ysize else img_ysize - y_offset
if sqterm < 0: print "MinError(I): not converging. (1)" return t # The updated threshold is the integer part of the solution of the # quadratic equation t_prev = t temp = (w1 + np.sqrt(sqterm)) / w0 if isnan(temp): print "MinError(I): not converging. (2)" t = t_prev else: t = int(floor(temp)) return t # open image, convert to dB, and shift to positive values DIR = 'C:/Data/Tewkesbury-LiDAR' img = IO.read(DIR + '/subset.data/Sigma0_HH_slv1_25Jul2007.img') img_db = 10 * np.log10(img) img_db_int = np.round(img_db).astype(int) img_db_int_pos = img_db_int + abs(np.min(img_db_int)) # calculate threshold n = np.max(img_db_int_pos) # 255 threshold = min_error_thresholding(img_db_int_pos.ravel(), n) print 'threshold:', threshold
#!/usr/bin/env python from skimage.filters import threshold_otsu from geotiff.io import IO # load original image img = IO.read('C:/Data/namibia-flipped.data/Sigma0_HH.img') # otsu thresholding of the original image threshold = threshold_otsu(img) img_thresholded = img > threshold IO.write(img_thresholded, 'C:/Data/namibia-flipped-thresholded.tif') print 'Threshold for original image:', threshold