Search code examples
matlabimage-processingcoding-stylepixel

How to change image pixels values?


I have an image and I want to assign different value for each pixel location (x,y) as follow:

v(x,y) = a(y^2) + b(y) + c

where a, b, and c are parameters determined empirically.

How can I do that in matlab? I mean how can I change pixels values of an image there?


Solution

  • It appears you only want to change the image values based on the y coordinate, so create a new matrix y like this:

    y = (1:height)' * ones(1,width);
    

    where height and width are the size of your image:

    [height, width] = size(v);
    

    then create your image v:

    v = a.*(y.^2) + b.*y + c;
    

    This will work if a, b, and c are single values or matrices with the same size as y.

    Hopefully that is what you were asking for.