MATLAB: Investigating changing image contrast with differnt modulations

sinusoid function

What should I comment on change in contrast with changing A and B?
Let s(x,y) = A + B sin[2π(u0x + v0y)] be a 2D sinusoidal signal (image) with u0 and v0 representing the fundamental spatial frequency in x and y directions respectively. Plot s(x,y), sampled at Δx = Δy = 0.01, from 0 to 1.99 in both directions for the following values of u0, v0, A, and B, and comment on change in contrast with changing A and B:
a. u0 = 2 and v0 = 0, B = 0, A = 50
b. u0 = 2 and v0 = 0, B = 10, A = 50
c. u0 = 2 and v0 = 0, B = 25, A = 50
d. u0 = 2 and v0 = 0, B = 50, A = 50.
This is the matlab code I wrote:
dx=0:0.01:1.99;
dy=0:0.01:1.99;
%a.u0=2 and v0=0
u0=2;
v0=0;
%a.A(vertical shift)=50, B(Amplitude)=0
A=50;
B=0;
sxy=(A+B*(sin(2*pi*(u0*dx+v0*dy))));
subplot(2,2,1);
plot(dx,sxy,'k');
xlabel('0\leqx\leq1.99');
ylabel('s(x,y)');
title('Plot of sin(4\pix)+50');
%b.u0=2 and v0=0
u0=2;
v0=0;
%b.A(vertical shift)=50, B(Amplitude)=10
A=50;
B=10;
sxy=(A+B*(sin(2*pi*(u0*dx+v0*dy))));
subplot(2,2,2);
plot(dx,sxy,'k');
xlabel('0\leqx\leq1.99');
ylabel('s(x,y)');
title('Plot of 10sin(4\pix)+50');
%c.u0=2 and v0=0
u0=2;
v0=0;
%c.A(vertical shift)=50, B(Amplitude)=25
A=50;
B=25;
sxy=(A+B*(sin(2*pi*(u0*dx+v0*dy))));
subplot(2,2,3);
plot(dx,sxy,'k');
xlabel('0\leqx\leq1.99');
ylabel('s(x,y)');
title('Plot of 25sin(4\pix)+50');
%d.u0=2 and v0=0
u0=2;
v0=0;
%d.A(vertical shift)=50, B(Amplitude)=50
A=50;
B=50;
sxy=(A+B*(sin(2*pi*(u0*dx+v0*dy))));
subplot(2,2,4);
plot(dx,sxy,'k');
xlabel('0\leqx\leq1.99');
ylabel('s(x,y)');
title('Plot of 50sin(4\pix)+50');

Best Answer

Sort of close, but you're not creating an image like they want. I think you need to create an image and then display it with imshow(), more like this:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
format longg;
format compact;
fontSize = 20;
dx=0:0.01:1.99;
dy=0:0.01:1.99;
numberOfColumns = length(dx);
numberOfRows = length(dy);
sxy = zeros(numberOfRows, numberOfColumns);
%a.u0=2 and v0=0
u0=2;
v0=0;
%a.A(vertical shift)=50, B(Amplitude)=0
A=50;
B=0;
for row = 1 : numberOfRows
dyThisRow = dy(row);
s = sin(2*pi*(u0.*dx+v0*dyThisRow));
thisRow = (A+B*(sin(2*pi*(u0.*dx+v0*dyThisRow))));
sxy(row,:) = thisRow;
end
subplot(2,2,1);
imshow(sxy, [0 75]);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
xlabel('0\leqx\leq1.99', 'FontSize', fontSize);
title('Plot of sin(4\pix)+50', 'FontSize', fontSize);
%b.u0=2 and v0=0
u0=2;
v0=0;
%b.A(vertical shift)=50, B(Amplitude)=10
A=50;
B=10;
for row = 1 : numberOfRows
dyThisRow = dy(row);
thisRow = (A+B*(sin(2*pi*(u0.*dx+v0*dyThisRow))));
sxy(row,:) = thisRow;
end
subplot(2,2,2);
imshow(sxy, [0 75]);
xlabel('0\leqx\leq1.99', 'FontSize', fontSize);
title('Plot of 10sin(4\pix)+50', 'FontSize', fontSize);
%c.u0=2 and v0=0
u0=2;
v0=0;
%c.A(vertical shift)=50, B(Amplitude)=25
A=50;
B=25;
for row = 1 : numberOfRows
dyThisRow = dy(row);
thisRow = (A+B*(sin(2*pi*(u0.*dx+v0*dyThisRow))));
sxy(row,:) = thisRow;
end
subplot(2,2,3);
imshow(sxy, [0 75]);
xlabel('0\leqx\leq1.99', 'FontSize', fontSize);
title('Plot of 25sin(4\pix)+50', 'FontSize', fontSize);
%d.u0=2 and v0=0
u0=2;
v0=0;
%d.A(vertical shift)=50, B(Amplitude)=50
A=50;
B=50;
for row = 1 : numberOfRows
dyThisRow = dy(row);
thisRow = (A+B*(sin(2*pi*(u0.*dx+v0*dyThisRow))));
sxy(row,:) = thisRow;
end
subplot(2,2,4);
imshow(sxy, []);
xlabel('0\leqx\leq1.99', 'FontSize', fontSize);
ylabel('s(x,y)', 'FontSize', fontSize);
title('Plot of 50sin(4\pix)+50', 'FontSize', fontSize);
Related Question