What are you doing with c? Nothing. Anyway, c will be the same as the original b. Where are you actually displaying the images and assigning the titles? That code is not shown.
Do not assign x and y (or any loop iterator variable) inside the loop. The for line takes care of incrementing them so there is no need for you to do it manually.
In your b(x, y, :) you reversed x and y. It should be b(y, x, :) because y is the row and x is the column and arrays are indexed b(row, column, colorChannel)
t is uint8 so it will never get more than 255 so there is no need to check for that. It will just automatically clip it to 255.
When you say
you're assuming b is an RGB image, though it might not be and the code will work even if it's color. However when you say
if t came from a RGB image then t will be a 3 element vector and the if doesn't really make sense