What function to be use in place of randn() function ?
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens

K=64;
gain= 1;
% %Reading host image from file
% file read
A = imread('lena.jpg');
%2. choosing file
%image_format=input...
%('Choose host image format [j] for *.jpg [b] for *.bmp [j] [b]: ','s');
%if image_format=='j'
% buffer=pwd;
% [plik, path] = uigetfile('*.jpg','Read file');
% cd(path);
%A=imread(plik);
%cd(path);
%elseif image_format=='b'
% buffer=pwd;
% [plik, path] = uigetfile('*.bmp','Read file');
% cd(path);
%A=imread(plik);
%cd(path);
%end
if length(size(A)) > 2
A = rgb2ycbcr(A); %if A is color image, not in a greyscale
B = double(A(:,:,1));
else
B = double(A);
end
%ENCODING
[M,N] = size(B);
%random additional information creation (with the respect
%of algorithm spatial domain)
Mb = (M/K);
Nb = (N/K);
plusminus1 = sign(randn(1,Mb*Nb));
Watermark = zeros(size(B));
for i = 1:Mb
for j = 1:Nb
Watermark((i-1)*K+1:i*K,(j-1)*K+1:j*K) = plusminus1(i*j);
end
end
Getting error in using the randn() function. What function to be use in place of randn() function ?
0 commentaires
Réponses (2)
John D'Errico
le 4 Mar 2018
Modifié(e) : John D'Errico
le 4 Mar 2018
Be serious.
You cannot generate a non-integer NUMBER of random numbers.
Mb = (M/K);
Nb = (N/K);
plusminus1 = sign(randn(1,Mb*Nb));
If it is true that the product Mb*Nb is not an integer, what do you expect? You chose K arbitrarily, although we are not told the size of B.
For example could you generate 1.5 random numbers? Would you expect any tool to be able to do that?
The error is not in randn, but in how you want to use it.
0 commentaires
Walter Roberson
le 4 Mar 2018
rand() is symmetric around 0. There is a 50% chance that the value returned is greater than 0. You can therefore instead use
plusminus1 = 2 * rand(1,Mb*Nb) - 1;
Hint: it won't work either, because the error is in what you are trying to do rather than in randn()
3 commentaires
Walter Roberson
le 5 Mar 2018
Your code assumes that your input image is a multiple of K pixels horizontal and vertical. What if that is not the case?
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
