Write a function to show a square “random” image. The function will take in “at least” one input argument which is the size of the image in pixels. As a default, the image will be shown in black-white. If a second input argument is provided, it will
Show older comments
This is what I have so far:
function week7hw1(pixels, varargin)
%This function will receive the size of the pixels as an input
%if a second input is entered, the image will be the colormap
n=nargin;
mat=randi(pixels);
if n==0
image(mat)
elseif n==1;
colormap(varargin)
image(mat)
end
end
I'm not sure what I am doing wrong for this function.
Accepted Answer
More Answers (1)
KALYAN ACHARJYA
on 21 Jul 2019
Edited: KALYAN ACHARJYA
on 21 Jul 2019
function image1=rand_image()
pixel_num=input('Enter the value ');
image1=logical(randi(2,[pixel_num pixel_num])-1); %@Image Analyst Answer
imshow(image1);
end
Command Window:
>> y=rand_image();
Enter the value 100
Figure Window:

Second Part is not complete-
If a second input argument is provided, it will
3 Comments
Caitlin Schmidt
on 21 Jul 2019
KALYAN ACHARJYA
on 21 Jul 2019
Edited: KALYAN ACHARJYA
on 21 Jul 2019
function image1=rand_image(pixel_num)
image1=logical(randi(2,[pixel_num pixel_num])-1); %@Image Analyst Answer
imshow(image1);
end
Now pass the pixel value from here
y=rand_image(100)
Caitlin Schmidt
on 21 Jul 2019
Edited: Caitlin Schmidt
on 21 Jul 2019
Categories
Find more on Color and Styling in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!