Reputation: 29
I have buttons that need to increase\decrease an colour level for RGB. Tried doing something like this
im3 = im3(:,:,1) + 2;
but it creates some weird image glitch. any ideas? i'm not a pro so i'm probably going about this all wrong but any pointers would be much appreciated.
Upvotes: 2
Views: 948
Reputation: 6569
There are a few things that you should consider:
im3 = im3(:,:,1) + 2;
assigns the new value to img3
variable and makes it a 2D matrix. You should do im3(:,:,1) = im3(:,:,1) + 2;
. to increase all the values by 2 in third channel.imadd
.double
or type uint8
. If the values are double
, the values are real and in between 0 and 1. If the values are unit8
, the values are integers in between 0 and 255. Adding by 2 is reasonable if the type is uint8
, but it is not when the type is double
. You should add by 2/255 if so. You can use im2double
or im2uint8
for type conversions with proper scaling. Be aware of the class of the img
variable by running class(img)
.Upvotes: 1