ABC2013
ABC2013

Reputation: 162

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?

Upvotes: 1

Views: 2036

Answers (2)

R.Falque
R.Falque

Reputation: 944

Speaking of image and pixel is misleading in your case (it seems you are just speaking about matrix). Try to run this code:

a = 1; b = 2; c = 3;
x = 1:100; % x and y define from 1 to the value for the size of your matrix
y = 1:100;
[X, Y] = meshgrid(x,y);

You can then get the value V with the following code:

V = a * Y.^2 + b * Y + c;

And plot it with:

figure;
imagesc(V);

Cheers

Upvotes: 1

Ayb4btu
Ayb4btu

Reputation: 3398

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.

Upvotes: 2

Related Questions