This question is from Matlab A Practical Introduction to Pro
This question is from Matlab: A Practical Introduction to Programming and Problem Solving, 3rd edition. The specific problem is Exercise 13 of Chapter 13, which reads as follows:
It is sometimes difficult for the human eye to perceive the brightness of an object correctly. For example, In the figure below, the middle of both images is the same color, and yet, because of the surrounding colors, the one on the left looks lighter than the one on the right. Write a script to generate a Figure Window similar to this one. Two 3 x 3 matrices were created. Use sublot to display both images side by side (the axes shown here are the defaults). Use the RGB method.
Thanks!
Solution
clc;
 clear all;
 close all;
 %%% first create two 3x3 matrix using colormap
 cmap1=colormap;
 cmap2=colormap;
 cmap1=reshape(1:9,3,3); %%% reshape the two matrix into 3x3
 cmap2=reshape(1:9,3,3);
%%%%%% for both matrix the middle elements are given value 12.
%%%%% For the 1st image (cmap1) all other elements were given a value of 1
%%%similarly for the 2nd image (cmap2), all other elements were given a value 32
 cmap1(1:end)=1; %%% other elements value 1
 cmap1(2,2)=12; %%% middle element value 12
 cmap2(1:end)=32;   %%% other element value 32
 cmap2(2,2)=12;   %%% middle element value 12
 subplot(1,2,1)    %%%plot
 image(cmap1);
 subplot(1,2,2)
 image(cmap2);

