How to Make a square image of size= 256 * 256 and fill it diagonally with 11 black pixels and 20white pixels ?

clear all close all
for row=1:256 for col=1:256 a(row,col)=1
end
end
end
figure,imshow(a)

1 Comment

There will be 256 elements on the main diagonal, so how exactly do you want these 11 and 20 to be chosen?

Sign in to comment.

Answers (1)

Try this:
width = 256;
% Create some initial sample data (all 99's).
myArray = 99 * ones(width, width, 'uint8');
% Make 11 black pixels.
for k = 1 : 11
myArray(k,k) = 0;
end
% Make 20 white pixels.
for k = 12 : 31
myArray(k,k) = 255;
end

Categories

Asked:

on 15 Feb 2014

Answered:

on 15 Feb 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!