Question
a=imread('cameramen.jpg'); b= round(a./256); but i got binary bits like this 1 0 1 0 0 1 0 0 0 0 0 0 0 1 0 1 0 1 0 0 . . . 1 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 1 0 0 . . 1 0 1 0 1 0 0 0 0 0 0 0 but what i want is: b = (1 0 1 0 1 0 0 0 .....n)
Expert Answer
Neeta Dsouza
PhD Expert
Answered Aug 26, 2026
You question is very unclear due to imprecise language.
Are you intending to binarise the image? That is convert each pixel to a single 0 or 1, as you've done with your b = round(a / 256), which convert all pixels below intensity 128 to 0 and all above 127 to 1. Or as your watermarking tag and question title suggest, convert each pixel to a sequence of bits?
If the latter, the best course is actually not to do it and use matlab's bit wise operators. This will be much faster than converting to a matrix of bits and back.
Example, replace LSB of matrix with random 0 or 1:
orig_image = imread('cameraman.tif'); %demo image shipped with matlab
lsb_replacement = uint8(randi([0 1], size(orig_matrix))); %random replacement
%set lsb to 0 (with AND 254) and replace with OR:
new_image = bitor(bitand(orig_matrix, 254), lsb_replacement);
imshowpair(orig_image, new_image, 'montage')
isequal(bitget(new_image, 1), lsb_replacement) %should return true
100% Run Guarantee
3-Hour Fast-Track Delivery
Need a Custom Version or Complete Simulation for This Problem?
Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.
Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here
Related watermarking Questions & Solutions
Browse All →
Explore similar technical troubleshooting questions and verified MATLAB solutions:
Ready-to-Run MATLAB & Simulink Projects
Browse All Projects →