How do I make text color black when using the function insertText

조회 수: 26 (최근 30일)
fadams18
fadams18 2020년 2월 3일
댓글: Image Analyst 2020년 2월 4일
Hello I created a white image using the code below. and then i inserted a text. but the text has yellow background. I dont know where this is coming from
N=500;
M=500;
whiteImage = 255 * ones(N, M, 'uint8');
DD= insertText(whiteImage, [100,234],'Hello World','FontSize',18,'TextColor','black');
imshow(DD);
Please help, how do I remove the yellow background under the text

채택된 답변

dpb
dpb 2020년 2월 3일
Read the rest of the documentation...
'BoxColor' Text box color
'yellow' (default) | character vector | cell array of character vectors | [R G B] vector | M-by-3 matrix
Use
DD= insertText(whiteImage, [100,234],'Hello World','FontSize',18,'TextColor','black','BoxColor','white');
It seems a more logical 'Default' choice would be the existing background color of the image, but I guess that's probably more difficult to ascertain...
  댓글 수: 8
fadams18
fadams18 2020년 2월 4일
It works. Lastly before i stop disturbing u.
Do you reckon this method as a good way to make an image mask?
The plan is to get this image 'mask1.png' and use it as a mask on an input image(Left) to produce the output in image(right)
Input=im2double(imread('dataset/3.jpg'));
mask = double( mat2gray( im2double(imread('dataset/mask1.png')) ) == 1 );
if size(mask,3)==1 && size(input,3)>1
mask = repmat(mask,[1,1,size(input,3)]);
end
output = mask.*Input ;
basically im just trying to recreate this
ff.jpeg
Image Analyst
Image Analyst 2020년 2월 4일
Depends on whether you want to do a weighted average of the images, or if you want to do masking. You're doing masking where you'll set the underlying image to pure black wherever your other image is equal to 1. Try it and see if this is what you want. I would probably suggest a weighted sum though, like 0.7 of one image plus 0.3 of the other image.

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

추가 답변 (1개)

Image Analyst
Image Analyst 2020년 2월 3일
It comes from the 'BoxColor' option. See the documentation. To have background be white:
N=500;
M=500;
whiteImage = 255 * ones(N, M, 'uint8');
DD= insertText(whiteImage, [100,234],'Hello World','FontSize',18,'TextColor','black', 'BoxColor', 'white');
imshow(DD);

Community Treasure Hunt

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

Start Hunting!

Translated by