Create a simple rectangular image

조회 수: 3 (최근 30일)
Tim van Schaik
Tim van Schaik 2021년 5월 4일
편집: DGM 2021년 5월 5일
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?

답변 (3개)

Walter Roberson
Walter Roberson 2021년 5월 4일
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 2021년 5월 4일
편집: Image Analyst 2021년 5월 4일
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 2021년 5월 5일
편집: DGM 2021년 5월 5일
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

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by