ThomasWangWeiHong / Shadow-Detection-Algorithm-for-Aerial-and-Satellite-Images

Python implementation of shadow detection and correction algorithm proposed in academia
41 stars 11 forks source link

Pixel size of output shadow_mask image #5

Closed zygym closed 3 years ago

zygym commented 3 years ago

Hi @ThomasWangWeiHong : The code helped me to extract the shadow of the image, however, it seems that the output shadow_image pixel size was not the same as the input image file, I am confused about how to align the output and input image pixel size? image It also notes that although the code was successfully debugged, some warning information appeared, is that information relative to the output image pixel size? image

Many thanks!

ThomasWangWeiHong commented 3 years ago

Hi @zygym,

Regarding the image pixel size difference, if you have used the function that I have written (as it is without any form of modification), the output and input image pixel size should be the same as the rasterio package automatically handles all the metadata about image height, width and resolution, and I have not changed the metadata itself (except for the part where I specified that the output only contains 1 channel instead of the 3 channels for the input image, i.e. "metadata['count'] = 1"). This means that the image pixel size should not be different for both input and output. My guess is that you are viewing the files in a viewer (such as windows photos etc.) different from the one that I usually use for remote sensing images (QGIS in this case), the shadow mask file might not be displayed by the viewer properly, resulting in the anomaly which you have attached in the query above (note that the shadow mask file is a binary filled only with 0s and 1s, which might not be properly displayed by normal viewers which are designed to work from the range of 0 to 255).

If I am also interpreting this correctly, perhaps you are wondering why does the resulting shadow mask look squarish and unnatural? If this is the case, then this issue is most likely linked to the clustering algorithm itself (i.e. K-Means). In my demo image in the .README section, I used INRIA images (taken by drones with a resolution of < 0.5m) while in your case, your image looks like it is taken from satellites with a resolution of about 1m (pansharpened if I am guessing it correctly). My speculation is that since my demo image has a higher resolution, the image would contain a lot more pixels (and thus local feature information) than yours, which would benefit algorithms such as the K-Means. As such, for your image, the K-Means might not be as effective in picking up some of the shadow pixels as compared to my demo images, thus resulting in some shadow pixels remaining unidentified, thus resulting in the squarish, unnatural shape of the shadow mask. The above explanation is only my speculation, and I believe it would be better to consult with a geospatial expert with regards to the actual cause of the observed phenomenon.

Also, for the warning messages displayed, I believe it is just to inform you that certain features supported by the rasterio package will not be written to file (.jpg in this case ), and definitely has nothing to do with image pixel size.