I want to draw a circle in this 500x500 black matrix, but it deos not appear idk
here is the code
E = zeros(500,500);
E2 = insertShape(E, 'Circle',[250 250 100], ...
'Color','white', 'LineWidth',5);
figure(5),imshow(uint8(E2));

 채택된 답변

Voss
Voss 2022년 3월 6일

1 개 추천

E = zeros(500,500);
E2 = insertShape(E, 'Circle',[250 250 100], ...
'Color','white', 'LineWidth',5);
figure(5);
% imshow(uint8(255*E2));
% or:
imshow(E2);

댓글 수: 4

Maha Almuaikel
Maha Almuaikel 2022년 3월 6일
Can I ask you why did you delete uint8?
Voss
Voss 2022년 3월 6일
E2 is a double matrix with values between 0 and 1.
uint8(E2) gives you a uint8 matrix with values between 0 and 1.
uint8([0 0 0]) is black, and uint8([1 1 1]) is very close to black.
uint8([255 255 255]) is white, which is what you want, so either multiply by 255 before doing uint8() (so that 0 goes to 0 and 1 goes to 255) or just use the double values (between 0 and 1) as they already are.
Do you need double? You just cast the whole thing to double at the end, so why didn't you like my solution where I just start out with the matrix being double right from the start, thus avoiding the need to cast it to double?
Or you can leave it as double - don't cast to uint8 - and it works fine:
E = zeros(500,500);
E2 = insertShape(E, 'Circle',[250 250 100], ...
'Color','white', 'LineWidth',5);
figure(5),imshow(E2);
Maha Almuaikel
Maha Almuaikel 2022년 3월 6일
@_ @Image Analyst Thank you! got it

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Image Analyst
Image Analyst 2022년 3월 6일

1 개 추천

Try this:
E = zeros(500,500, 'uint8'); % Make image as uint8 right from the beginning.
E2 = insertShape(E, 'Circle', [250 250 100], ...
'Color','white', 'LineWidth',5);
imshow(E2, []); % Display it with [] to expand the contrast.

카테고리

도움말 센터File Exchange에서 Images에 대해 자세히 알아보기

질문:

2022년 3월 6일

댓글:

2022년 3월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by