Question

In: Computer Science

Using Matlab 1. Create a color image of size 200 × 200. The image should have...

Using Matlab

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.

Solutions

Expert Solution

clear;
clc;

% create a blue 200 x 200 image 
BImage=zeros(200,200,3);
BImage(:,:,1) = 0;
BImage(:,:,2) = 0;
BImage(:,:,3) = 1;

% show image
figure, imshow(BImage);
% generate random odd size of 100 rectangular regions
% initialize yellow_block verctor
% 1st row is for row size of block 
% 2nd row is for col size of block
% 3rd row is for block starting x co-ordinate
% 4th row is for block starting y co-ordinate
yellow_block = zeros(4, 100);

% initialize %
i = 1;

% random block size of m x n order where m, n belongs to [3, 5, 7]
total = size(yellow_block, 1)* size(yellow_block, 2);
while i <= total
    % loop until odd number is generated
    while 1
        r = randi([3, 7], 1);
        if mod(r, 2) == 1
            break;
        end
    end
    if mod(i, 2) == 1
        yellow_block(1, ceil(i/2))= r;
    else
        yellow_block(2, ceil(i/2))= r;
    end
    i = i+1;
end

% declare an array of 200 x 200 which tracks the 
%  reservation of pixel location by yellow blocks
% initialize
reserve = zeros(200);

% initialize %
i = 1;
% now reserve the location for each of yellow block 
while i <= 100
    while 1
        % generate random numbers for
        % co-ordinate of a yellow block
        x = randi([1, 200], 1);
        y = randi([1, 200], 1);
        % now find if the yellow block
        % covering a already reserved pixel
        if (x+yellow_block(1, i)-1) <= 200 && (y+yellow_block(2, i)-1) <= 200
            s = sum(sum(reserve(x:(x + yellow_block(1, i)-1), y:(y + yellow_block(2, i)-1))));
            if s == 0
                % make the location reserved
                reserve(x : (x+yellow_block(1, i)-1), y : (y+yellow_block(2, i)-1)) = 1;
                % set origin pixel of yellow block
                yellow_block(3, i) = x;
                yellow_block(4, i) = y;
                break;
            end
        end
    end
    i = i+1;
end
% 
i = 1;
% make the blocks yelllow color
while i <= 100
    BImage(yellow_block(3, i):(yellow_block(3, i) + yellow_block(1, i)-1), ...
        yellow_block(4, i):(yellow_block(4, i) + yellow_block(2, i)-1) ,3)=0;
    BImage(yellow_block(3, i):(yellow_block(3, i) + yellow_block(1, i)-1), ...
        yellow_block(4, i):(yellow_block(4, i) + yellow_block(2, i)-1) ,1)=1;
     BImage(yellow_block(3, i):(yellow_block(3, i) + yellow_block(1, i)-1), ...
        yellow_block(4, i):(yellow_block(4, i) + yellow_block(2, i)-1) ,2)=1;
   
    i = i + 1;
end
% display image
figure, imshow(BImage);

___________________________________________________________________


___________________________________________________________________

___________________________________________________________________

Note: If you have queries or confusion regarding this question, please leave a comment. I would be happy to help you. If you find it to be useful, please upvote.


Related Solutions

1. Create a color image of size 200 × 200. The image should have a blue...
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 ×...
I want to create an image compression program with matlab use PCA. I have the code...
I want to create an image compression program with matlab use PCA. I have the code listed below. But this code is fail, the image is colorless, but still gray. Can you help me to fix my code. clc clear all picture = im2double(imread('picture1.jpg')); Red = picture(:,:,1); premean = mean(Red(:)); premax = max(Red(:)); premin = min(Red(:)); x = size(Red,1); y = size(Red,2); Z = ones(x,y)*premean; A = (Red - Z)*(1/premax - premin); B = cov(A); [veceig,eig,C] = pcacov(B); NewRed =...
1-Pupils should be black in color, equal in size, normally 3-7 mm in diameter and have...
1-Pupils should be black in color, equal in size, normally 3-7 mm in diameter and have smooth border. -true -false 2-cilyball whist In order to assess the client respiratory system especially if he or she is suspected to have extra fluid around or inside lungs, we ask the client to repeat such words as "blue moon" or "one, two, three'. The terminology used to describe this technique is a. Respiratory auscultation. b. Tactile fremitus. C. Thoracentesis. d. Respiratory excursion. 3-The...
MATLAB code: using Laplacian mask enhance for image "ngc6543.jpg".
MATLAB code: using Laplacian mask enhance for image "ngc6543.jpg".
Draw a Koch Snowflake fractal image using MATLAB programming. I'm pretty new to MATLAB and im...
Draw a Koch Snowflake fractal image using MATLAB programming. I'm pretty new to MATLAB and im not too familar with how all the plotting and drawing functions work.
1- Write a Matlab program to perform image resizing, image rotation to 90 degrees, conversion to...
1- Write a Matlab program to perform image resizing, image rotation to 90 degrees, conversion to binary and gray scale, Image segmentation and extraction, draw and find the region of interest with a circle, Plot bounding box, Region extraction and histogram. 2- Write a MATLAB program to Design a GUI calculator which is as shown in below figure 1. Add tool bar options to the GUI calculator and Highlight specific codes written in program and signify the steps followed.
Using MATLAB (a) Write a computer program capable of zooming and shrinking an image by pixel...
Using MATLAB (a) Write a computer program capable of zooming and shrinking an image by pixel replication. Assume that the desired zoom/shrink factors are integers.
a. Using Matlab scripts create the following matrices (???1 and ???2) ???1 = [ 3 2...
a. Using Matlab scripts create the following matrices (???1 and ???2) ???1 = [ 3 2 −3 6 7 4 3 −6 7 ], ???2 = [ 2 1 7 3 3 9 −6 6 1 ]    b. Write code to add the second row of ???1 to the third row of ???2 and store results in the first row of ???1. c. Write code to add the second column of ???1 with the third column of ???2 and...
By using MATLAB 1. Divide a speech signal or music signal into frames of size N...
By using MATLAB 1. Divide a speech signal or music signal into frames of size N = 64. 2. Compute the N?point DFT of each frame. 3. Save only first L = 20 DFT coefficients. 4. Reconstruct the frame from these L coefficients. (Do not disturb the symmetry of DFT during inverse DFT computation. X[k] = X[N ?k] for real signals, N = 64 here. Pad zeros for missing DFT coefficients.) 5. Comment on the quality of reconstructed and the...
Matlab question: 1. Implement image filtering in frequency domain on the "testtpattern512.tif" image. You will design...
Matlab question: 1. Implement image filtering in frequency domain on the "testtpattern512.tif" image. You will design the filter, and filter the image in the frequency domain, then use inverse DFT to display the filtered image in the spatial domain. Assume zero padding for filtering process. a- Design a rectangular ideal low pass filter with a cutoff frequency of (Uo, Vo), filtering the image so that the vertical lines are blurred together, horizontal lines are basically intact and the letters are...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT