Continuous monochrome image sampling

How can I sample a continuous monochrome image (f(x, y) = x(1 − y) + y(1 − x), 0 ≤ x ≤ 1, 0 ≤ y ≤ 1) to a discrete image with with 5 x 7 pixels by letting the lower left pixel be a sample from point (0,0) and the upper right from (1,1)?
How it could be quantify the discrete image with 32 different gray levels from 0 to 31??

 Accepted Answer

xvec = linspace(0,1,7); %x is columns
yvec = linspace(0,1,5); %y is rows
[X, Y] = meshgrid(xvec, yvec);
F = X.*(1-Y) + Y.*(1-X);
imagesc(F); colormap(gray)

4 Comments

Thanks, it was really helpful. But how it could be quantify with 32 different gray levels from 0 to 31??
You'd need to adjust the first 2 lines so that you have an array of 32, like
xvec = linspace(0,1,8); %x is columns
yvec = linspace(0,1,4); %y is rows
[X, Y] = meshgrid(xvec, yvec);
F = 32 * (X.*(1-Y) + Y.*(1-X)); % Gray levels range fromm 0 to 32.
imagesc(F);
colormap(gray);
%impixelinfo; % Uncomment in your own code (can't be used online).
For the case where what you care about is 32 gray levels
xvec = linspace(0,1,7); %x is columns
yvec = linspace(0,1,5); %y is rows
[X, Y] = meshgrid(xvec, yvec);
F = X.*(1-Y) + Y.*(1-X);
imagesc(F); colormap(gray(32))
For the case where you do care about the array being represented as 0 to 31
xvec = linspace(0,1,7); %x is columns
yvec = linspace(0,1,5); %y is rows
[X, Y] = meshgrid(xvec, yvec);
F = X.*(1-Y) + Y.*(1-X);
Fq = floor(rescale(F,0,32*(1-eps)));
imagesc(Fq); colormap(gray(32))
Thanks a lot :)

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Products

Release

R2022a

Community Treasure Hunt

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

Start Hunting!