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)
Show older comments
clear all close all
for row=1:256 for col=1:256 a(row,col)=1
end
end
end
figure,imshow(a)
1 Comment
Wayne King
on 15 Feb 2014
There will be 256 elements on the main diagonal, so how exactly do you want these 11 and 20 to be chosen?
Answers (1)
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
0 Comments
See Also
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!