binary vector function and hide image function erorr
15 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen

I have matlab project hide images in image and there are some erorr in code
Whare i want to run the project show me this erorr hide_image Used -0.0031705 percent of the source image. Embedded Image saved as : 'embedded.png' in the current directory. Subscript indices must either be real positive integers or logicals.
Error in hide_image>binary_vector (line 48) else
Error in hide_image (line 29) a11(:,1)=a11(:,1) + binary_vector(num_of_images);
the imgaes used in project
https://d.top4top.net/m_777vmc4d1.bmp
https://e.top4top.net/p_777lhd0x2.png
function hide_image(varargin)
num_of_images=nargin - 1;
all_images=[];
image1props=[];
szim=zeros(num_of_images,3);
check_limit=0;
for i=1:num_of_images
b=double(imread(char(varargin(i))));
szim(i,1)=size(b,1);szim(i,2)=size(b,2);szim(i,3)=size(b,3);
check_limit=check_limit+size(b,1)*size(b,2)*size(b,3);
all_images=[all_images reshape(b,1,size(b,1)*size(b,2)*size(b,3))];
end
for i=1:num_of_images
image1props=[image1props reshape([floor(szim(i,3)/3) binary_vector(szim(i,1))' zeros(1,15-length(binary_vector(szim(i,1)))) binary_vector(szim(i,2))' zeros(1,16-length(binary_vector(szim(i,2))))],8,4)];
end
next=4*num_of_images+1;
%--------------------------------------------------------------------------
a=double(imread('map1.bmp'));
percent_of_img_used=(100*8*(check_limit+4*num_of_images+1))/(size(a,1)*size(a,2)*size(a,3));
if percent_of_img_used >100
display_text=['Too Many Images or Too Big Image for Hiding [Used ' num2str(percent_of_img_used) ' percent of the source image].'];
error(display_text);
end
display_text = ['Used ' num2str(percent_of_img_used) ' percent of the source image. Embedded Image saved as : ''embedded.png'' in the current directory.'];
disp(display_text);
a2=[reshape(a,1,size(a,1)*size(a,2)*size(a,3)) zeros(1,8-rem(size(a,1)*size(a,2)*size(a,3),8))];
a11=2.*floor(reshape(a2,8,length(a2)/8)/2);
a11(:,1)=a11(:,1) + binary_vector(num_of_images);
a11(:,2:next)=a11(:,2:next) + image1props;
for j=1:num_of_images
b1=all_images(next-4*num_of_images:next-4*num_of_images-1+szim(j,1)*szim(j,2)*szim(j,3));
for i=1:length(b1)
a11(:,i+next)=a11(:,i+next)+ binary_vector(b1(i));
end
next=next+szim(j,1)*szim(j,2)*szim(j,3);
end
a111=reshape(a11,1,size(a11,1)*size(a11,2)*size(a11,3));
a111=a111(1:end-(8-rem(size(a,1)*size(a,2)*size(a,3),8)));
a22=reshape(a111,size(a,1),size(a,2),size(a,3));
imwrite(uint8(a22),'embedded.png');
%--------------------------------------------------------------------------
function out = binary_vector(in)
out=zeros(8,1);
if ~in
return;
else
while(1)
out(floor(log2(in))+1)=1;
in= in - power(2,floor(log2(in)));
if ~in
break;end
end
end
4 Kommentare
Guillaume
am 16 Feb. 2018
Your code works for me (in that it does not produces errors) if I do the following:
map1 = imread('https://e.top4top.net/p_777lhd0x2.png');
imwrite(map1, 'map1.bmp');
hide_image('https://d.top4top.net/m_777vmc4d1.bmp', ...
'https://d.top4top.net/m_777vmc4d1.bmp')
I'm giving it twice the same image since it needs at least two input images in addition to the map1.bmp image hardcoded.
Antworten (2)
Jan
am 16 Feb. 2018
Use the debugger to find the problem:
dbstop if error
Now run the code again and check the indices used in the failing line. The message is clear:
Subscript indices must either be real positive integers or logicals.
This means, that either you use a bad index, or that you want to use a function, e.g. "log2()", but this has been defined as variable before. See:
clear log2
log2(1.414) % Valid
log2 = 1:10;
log2(1.414) % Bad index
3 Kommentare
Jan
am 19 Feb. 2018
It is strange that so many commands are underlined in the editor. Check and fix the reasons for this.
I've suggested already to check the value of the index or if the used functions are overwritten by variables. Set a breakpoint in the failing line and examine, what's going on:
which out
size(out)
which floor
which log2
size(in)
in
log2(in) + 1
floor(log2(in) + 1)
Guillaume
am 16 Feb. 2018
Your screenshot in your comment to Jan's answer shows the complete error message. You removed the most important part of it in your question, leaving us no chance of being able to identify the problem. The crucial bit is
Error in hide_image>binary_vector (line 80)
out(floor(log2(in))+1)=1;
That is the line producing the error. The rest of the call stack in this instance is not important.
out is defined as a vector with 8 elements, so if you're getting this error it's because floor(log2(in))+1 is greater than 8. This can only happen if in is greater than 255.
Since you never check that your images are indeed 8-bit per channel, if your code is given an image with 16-bit per channels (which can happen with some png and tif images) it will fail.
2 Kommentare
Guillaume
am 19 Feb. 2018
Error in hide_image (line 18) a=double(imread('pano.jpg','map1.bmp','faces.bmp','house.jpg'));
imread has never supported giving it several images at once, so it's no wonder you get an error.
I don't know why you modified that part of the original code which worked fine.
Siehe auch
Kategorien
Mehr zu Audio and Video Data finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



