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

5 views (last 30 days)
clear all close all
for row=1:256 for col=1:256 a(row,col)=1
end
end
end
figure,imshow(a)

Answers (1)

Image Analyst
Image Analyst on 15 Feb 2014
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

Find more on Loops and Conditional Statements 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!