In: Computer Science
1. Create a color image of size 200 × 200. The image should have a blue background.
2. Create 100 yellow regions within the image that have a variable size. More specifically, their width should be an odd number and vary between 3 and 7 and their height should also be an odd number and vary between 3 and 7. For example, you may get rectangular regions of size 3 × 3, 3 × 5, 5 × 3, 5 × 5, 7 × 5, etc. These 100 yellow regions should be placed at random locations within the 200 × 200 image, but we should make sure that they do not overlap with each other. Important: These regions should be created by modifying the image pixels, and not as plots on top of the image. In other words, these regions should be part of the image.
3. Plot horizontal and vertical white lines on top of the image for every 40 pixel rows and every 40 pixel columns. Now, these white lines will not be part of the image, but an extra layer on top of the image. You may use hold on and hold off, and also plot to achieve this. Display the image with the yellow regions and the white lines in figure(1).
This is what i have for 1 and 2, which is working correctly
clear all;
close all;
clc;
im=zeros(200,200,3);%image
im(:,:,3)=1;
for i=1:100
while true;
w=2*round(1+2*rand(1,1))+1;
h=2*round(1+2*rand(1,1))+1;
x=round(1+(199-w)*rand(1,100));
y=round(1+(199-h).*rand(1,100));
x_dash=x+w;
y_dash=y+h;
if all(im(x:x_dash,y:y_dash,2)!=1)
im(x:x_dash,y:y_dash,3)=0;
im(x:x_dash,y:y_dash,1:2)=1;
break;
end
end
end
Need help with Part 3
Following is the complete code in image_yellow_white.m :
clear all;
close all;
clc;
im=zeros(200,200,3);%image
im(:,:,3)=1;
for i=1:100
while true;
w=2*round(1+2*rand(1,1))+1;
h=2*round(1+2*rand(1,1))+1;
x=round(1+(199-w)*rand(1,100));
y=round(1+(199-h).*rand(1,100));
x_dash=x+w;
y_dash=y+h;
if all(im(x:x_dash,y:y_dash,2)~=1)
im(x:x_dash,y:y_dash,3)=0;
im(x:x_dash,y:y_dash,1:2)=1;
break;
end
end
end
imshow(im);
%
% Part 3
%
%
% Create a copy of current image.
%
im2 = im;
%
% Extract the size of image.
%
[numRows numColumns numDepth] = size(im2);
%
% Set every 40th row as white.
%
im2(1 : 40 : numRows, :, :) = 1;
%
% Set every 40th column as white.
%
im2(:, 1 : 40 : numColumns, :) = 1;
%
% Hold on, and draw (superimpose) this second image.
%
hold on;
imshow(im2);
Following is the run :
>>
>> image_yellow_white