# Why does part of my image turn black when applying functions to a part of an image in Matlab?

When I select a part of an image and apply a negative function to it, it works 100%:

When trying to apply the same method using another function, the part of image becomes black:

What is the problem and how can I fix it?

Check the elements in your x, make sure they are not zeros. Then selectedArea=uint8(x);