Create a simple rectangular image
Show older comments
So I was wondering if I could create a small image of 100x100 pixels where the outside is dark whilst the inside is completely clear (1's) I know how to fill a matrix by doing zeroes(100,100) but I now want to replace within this area a space of ones(40,60) but How do i exactly overlay this?
Answers (3)
Walter Roberson
on 4 May 2021
img(row_white_start:row_white_start+num_white_rows-1, col_white_start:col_white_start+num_white_cols-1) = 1;
Image Analyst
on 4 May 2021
Edited: Image Analyst
on 4 May 2021
Do you want to overlay an image or replace the image there? You said it both ways.
Do you mean like this:
img = zeros(100, 100);
img(31:70, 21:80) = 1
imshow(img, [], 'InitialMagnification', 1000);
grid on;
axis('on', 'image');
If you're describing a white image with a black border, then I'll offer a different method:
testpict = padarray(ones(40,60),[30 20]);
EDIT: If you don't have Image Processing Toolbox and you still want to use something with a convenient syntax, MIMT has you covered.
testpict1 = padarrayFB(ones(40,60),[30 20]); % works with or without IPT
testpict2 = addborder(ones(40,60),[30 20]); % addborder can do the same things as padarray()
testpict3 = addborder(ones(40,60,3),[20 40 30 10],[0.12 0.23 0.5]); % but it can do many other things too
Categories
Find more on Image Arithmetic 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!