truecolor error in changing RGB of pixels
Show older comments
Hi, Ive been trying to change the pixels of an image but I get an error everytime I try to change something other than red. For example, red=20, blue=0, green=0 works. However, red=10 blue=10 green=50 doesnt work. The error I get is
Error using image
TrueColor CData contains element out of range 0.0 <= value <= 1.0
Error in changeRGB (line 19)
image(pic) %show image
This is the code
name= input('Enter name of file: \n', 's'); %file name
format= input ('Enter format of file: \n', 's');%file format
redchange = input('Change in percent of red: \n');%red change
bluechange = input ('Change in percent of blue: \n');%blue change
greenchange = input ('Change in percent of green: \n');%green change
pic= imread(name, format); %reading image
pic= double(pic); %converting to doubles
pic=pic/255; %scaling everything by dividing by 255.
pic(:,:,1)= redchange*pic(:,:,1); %multiply the values by percentage
pic(pic(:,:,1)>1)=1; %changing all values over 1 equal to one
pic(:,:,2)= greenchange*pic(:,:,2); %multiply the values by percentage
pic(pic(:,:,2)>1)=1; %changing all values over 1 equal to one
pic(:,:,3)= bluechange*pic(:,:,3); %multiply the values by percentage
pic(pic(:,:,3)>1)=1; %changing all values over 1 equal to one
image(pic) %show image
axis off %no axis
Accepted Answer
More Answers (0)
Categories
Find more on Get Started with Image Processing Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!