My project is about "Extracting water and urban features from satellite images". I have extracted urban and water features using Python code. Now, I want to do accuracy assessment. I know two primary requirements for accuracy are reference data and predicted data. So, as reference data I have GeoTIFF file and as predicted data I have my extracted image (GeoTIFF format). I tried with accuracy assessment using Python but I am getting accuracy as 99% which is not possible. Can somebody suggest how I can achieve this using Python?
Please find my code:
import numpy as np import matplotlib.pyplot as plt import cv2 from PIL import Image import os import gdal import osr gtif = gdal.Open('E:\\tanvi_iirs_work\\Task 3\\Images\\geosample.tif') srcband = gtif.GetRasterBand(1) trans = gtif.GetGeoTransform() proj = gtif.GetProjection() #print(proj) #print("1") arr1=srcband.ReadAsArray() arr = srcband.ReadAsArray() print("urban area") #Extracting urban area for i in range(arr.shape): for j in range(arr.shape): if 0.6 <= arr[i,j] <= 1: arr[i,j] = 1 else: arr[i,j] = 0 plt.imshow(arr,cmap = 'gray') cols = arr.shape rows = arr.shape driver = gdal.GetDriverByName('GTiff') if arr.ndim == 2: band_num = 1 else: band_num = arr.shape outRaster = driver.Create('E:\\tanvi_iirs_work\\Task 3\\Images\\outputtrial1.tif',cols,rows,1,gdal.GDT_Float32) outRaster.SetGeoTransform(trans) #srs = osr.SpatialReference() #s1 = srs.ImportFromEPSG(4326) #print(srs) outRaster.SetProjection(proj) #print(outRaster.GetProjection()) outband = outRaster.GetRasterBand(1) outband.WriteArray(arr) #data2 = outband.ReadAsArray() #print(data2) outband.FlushCache() outRaster=None #Accuracy Assessment tp=0 fp=0 tn=0 fn=0 for i in range(arr.shape): for j in range(arr.shape): if arr[i][j]==1 and 0.5=<arr1[i][j]<=1: tp+=1 if arr[i][j]==0 and 0.0=<arr1[i][j]<=0.4: fp+=1 if arr[i][j]==1 and 0.5=<arr1[i][j]<=1: tn+=1 if arr[i][j]==0 and 0.0=<arr1[i][j]<=0.4: fn+=1 print(tp,tn,fp,fn) acc=(tp+tn)/(tp+tn+fp+fn) print(acc*100)