How to change pixel intensity in a color picture

2 views (last 30 days)
I have a color image in which I want to reduce the intensity of the leftmost vertical third of the picture by 100, and increase the rightmost vertical third of the picture by 100. (This is for a class project, btw.) I've tried implementing the below code, but all it seems to do is make it more or less red, as opposed to lighter or darker. How can I fix this? edit: The function takes in an image array, img, where the values are from 0 to 255.
function [quant] = imgChange(img)
quant = img;
s = size(img);
third_left = round(s(2)/3);
third_right = third_left * 2;
quant(:,1:third_left) = quant(:,1:third_left) - 100;
quant(:,third_right:s(2)) = quant(:,third_right:s(2)) + 100;
end

Accepted Answer

Guillaume
Guillaume on 30 Nov 2016
Well, yes, if your image is RGB, you have 3 colour planes in the third dimension. You need to tell matlab that you want to affect all three, so:
quant(:,1:third_left, :) = quant(:,1:third_left, :) - 100;
quant(:,third_right:s(2), :) = quant(:,third_right:s(2), :) + 100;

More Answers (0)

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!