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?

Réponses (1)

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);

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by