doc blockproc
It operates given function on an image block by block, so will get rid of the code you wrote above to partition the image. And std gives standard deviation.
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!