What function to be use in place of randn() function ?

6 visualizaciones (últimos 30 días)
Developer Developer
Developer Developer el 4 de Mzo. de 2018
Comentada: Walter Roberson el 5 de Mzo. de 2018
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 ?

Respuestas (2)

John D'Errico
John D'Errico el 4 de Mzo. de 2018
Editada: John D'Errico el 4 de Mzo. de 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.

Walter Roberson
Walter Roberson el 4 de Mzo. de 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 comentarios
Developer Developer
Developer Developer el 4 de Mzo. de 2018
Editada: Developer Developer el 4 de Mzo. de 2018
above is the error and i tried replacing error code with your code but yes you are right, it won't work either. I have edited the question. Please check it again.
Walter Roberson
Walter Roberson el 5 de Mzo. de 2018
Your code assumes that your input image is a multiple of K pixels horizontal and vertical. What if that is not the case?

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by