adjust percentage of red green blue in RGB

hi,
I need to change the percentage color for a picture between red green blue. For example, when I put a number, like 50% of red. The picture should show more red. moreover, when I need to show 30% less blue, the picture should be less blue. However, I don't know how to set up how many percentage will change in the picture. I am using imread to run out the file.
Here is what I got.
filename= input(Enter the name of your file , s);
fileformat= input (Enter the format of your file , s);
Redpercent = input(The percent change in red level );
X= imread(filename, fileformat);
X= double(X);
X= X/255;
X(:,:,1)= 2*X(:,:,1);
X(X(:,:,1)>1)=1

 Accepted Answer

If you just want to amplify the red values by a factor of 1.5678 then:
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
% Multiply red by some factor:
amplitudeFactor = 1.5678; % Whatever you want.
redChannel = uint8(double(redChannel) * amplitudeFactor);
% Recombine separate color channels into a single, true color RGB image.
rgbImage = cat(3, redChannel, greenChannel, blueChannel);
imshow(rgbImage);
In your code, there is no reason to ask for the image file format and pass it in to imread unless the image does not have a file extension or the file extension is incorrect. If that's the case it would be better to correct that rather than to ask for format and pass it in. imread() will figure out the format from the filename extension.

3 Comments

david Chan
david Chan on 19 Oct 2014
Edited: david Chan on 19 Oct 2014
there is a requirement for calling up the file name which I can provide that it satisfy with any picture file. could you show me the way with 2-D, as I know it is 3D. I know i should scaled a image array which scaled by 255, and multiplying by a factor of percent/100, the percent should be a integer
I do not understand this at all. You can use uigetfile() to have the user select an existing filename. Color images are 3D and grayscale and indexed images are 2D. You can scale any image with mat2gray() or imadjust(). Other than that I can't figure out what you're asking. Please post images that illustrate what you're attempting to do.
I figure out that use this array "X(:,:,1)=X(:,:,1)* red percent/100" to change the percent of colour.
filename= input(Enter the name of your file , s);
fileformat= input (Enter the format of your file , s);
Redpercent = input(The percent change in red level );
X= imread(filename, fileformat);
X= double(X);
X= X/255;
X(:,:,1)=X(:,:,1)
Something like this. Anyway, thanks for you helping :)

Sign in to comment.

More Answers (0)

Categories

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!