Vectorisation to replace for loop: Steganography text hiding
이전 댓글 표시
Hi! I'm trying to get rid of the for loop in this piece of code to optimise it but I can't think of how. I've been trying with vectorisation but I'm new to Matlab so it hasn't been working. I have a table of randomised pixels where the text will be hidden in with the variable:
px
And the variable with the corresponding pixels' least significant bits is:
LSB
And here is the code where I perform the data hiding:
% Traverse table of pixels where data will be hidden
for i = 1 : size(LSB, 2)
% If the encoded binary of the current message bit==pixel's LSB,
% do nothing
if (LSB(i)==binaryTxt(i))
hidden(px(i)) = original(px(i));
elseif (LSB(i)==1)
hidden(px(i)) = original(px(i)) - 1;
elseif (LSB(i)==0)
hidden(px(i)) = original(px(i)) + 1;
end
end
Any suggestions on how to remove the for loop?
답변 (1개)
Bruno Luong
2022년 11월 15일
Second take:
d = nan(numel(px),1);
d(LSB===0) ) = 1;
d(LSB===1) ) = -1;
d(LSB==binaryTxt) = 0;
b = isfinit(d);
pxk = px(isfinite(d));
hidden(pxk) = originalpxk) +d(b);
카테고리
도움말 센터 및 File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!