What function to be use in place of randn() function ?
조회 수: 6 (최근 30일)
이전 댓글 표시

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
답변 (2개)
John D'Errico
2018년 3월 4일
편집: John D'Errico
2018년 3월 4일
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
Walter Roberson
2018년 3월 4일
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
Walter Roberson
2018년 3월 5일
Your code assumes that your input image is a multiple of K pixels horizontal and vertical. What if that is not the case?
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
