0

我正在寻找使用 matlab 将字符插入图像的代码。

img是我的封面图片,msg也是我的文字。我收到这个错误

Error using ==> bitset
Operands to BIT Ops must be numeric.

但我的是数字。它不是?我该如何说清楚?

clear all;
img=imread('img.jpg','jpg');
msgopen=fopen('ramz.txt');
msg=fread(msgopen);
msgbin=dec2bin(msg);
msgsize=size(msg);
x=msgsize(1);
msgsizebin=dec2bin(x,8);
imgh=size(img,1);
imgw=size(img,2);
for i=1:imgh;
  for j=1:imgw;
    img(i,j)=bitset(img(i,j),msgbin(i,1));
  end
end
4

1 回答 1

0

You can use the text function and then the hardcopy function to create the image with the text coded into the data;

img=imread('img.jpg','jpg');
msgopen=fopen('ramz.txt');
msg=fread(msgopen);
hfig=figure;
imshow(img);
hold on;
text(x_loc,y_loc,msg); %x_loc and y_loc are the locations where you want the text to   
                       % appear. msg is assumed to be a string.
orig_mode = get(hfig, 'PaperPositionMode');
set(hfig, 'PaperPositionMode', 'auto');
img_with_text = hardcopy(hfig, '-Dzbuffer', '-r0');
于 2013-04-07T08:27:48.753 回答