Create a simple rectangular image

7 vues (au cours des 30 derniers jours)
Tim van Schaik
Tim van Schaik le 4 Mai 2021
Modifié(e) : DGM le 5 Mai 2021
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?

Réponses (3)

Walter Roberson
Walter Roberson le 4 Mai 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
Image Analyst le 4 Mai 2021
Modifié(e) : Image Analyst le 4 Mai 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');

DGM
DGM le 5 Mai 2021
Modifié(e) : DGM le 5 Mai 2021
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

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by