Hi I'm trying to write some code that achieves the following using the image processing toolbox:
1. Split a grayscale image (I) into blocks
2. Calculate the mean value of each block
3. For each element within each block, if it's > the mean of that block colour it black, if not colour it white.
Here's what I want to say:
fun=@(block_struct)... for n=1:32 for m=1:32 if block_struct.data(n,m)>(mean2(block_struct.data)); block_struct.data(n,m)=0; else block_struct.data(n,m)=255; end end end I2=blockproc(I,[32 32],fun);imshow(I2)
However you cannot have anonymous functions with more than one statement and I'm not sure how to use a block structure with a normal function. I have looked a little into nested functions but I haven't found an answer yet. Any help would be appreciated.
Best Answer