How to remove error "Integers can only be combined with integers of the same class, or scalar doubles."

1 view (last 30 days)
When I'm using typecasting my image quality is affected and I'm not getting desired results. Here is my code:
clc
[file path]=uigetfile('*.*');
img=imread(file);
[r c p]=size(img);
[pl1 pl2 pl3 pl4 pl5 pl6 pl7 pl8]=bitplane_slice(img);
figure;
subplot(3,3,1);imshow(pl1);title('pln 1')
subplot(3,3,2);imshow(pl2);title('pln 2')
subplot(3,3,3);imshow(pl3);title('pln 3')
subplot(3,3,4);imshow(pl4);title('pln 4')
subplot(3,3,5);imshow(pl5);title('pln 5')
subplot(3,3,6);imshow(pl6);title('pln 6')
subplot(3,3,7);imshow(pl7);title('pln 7')
subplot(3,3,8);imshow(pl8);title('pln 8')
sec=imread('ab.png');
new_sec=imresize(sec,[r c]);
stego = new_sec+pl2*2+pl3*4+pl4*8+pl5*16+pl6*32+pl7*64+pl8*128;
figure;
subplot(1,2,1);imshow(new_sec);title('Sec image')
subplot(1,2,2);imshow(uint8(stego));title('Stego image')
[pl1 pl2 pl3 pl4 pl5 pl6 pl7 pl8]=bitplane_slice(stego);
figure;
subplot(3,3,1);imshow(pl1);title('pln 1')
subplot(3,3,2);imshow(pl2);title('pln 2')
subplot(3,3,3);imshow(pl3);title('pln 3')
subplot(3,3,4);imshow(pl4);title('pln 4')
subplot(3,3,5);imshow(pl5);title('pln 5')
subplot(3,3,6);imshow(pl6);title('pln 6')
subplot(3,3,7);imshow(pl7);title('pln 7')
subplot(3,3,8);imshow(pl8);title('pln 8')

Accepted Answer

Image Analyst
Image Analyst on 25 Dec 2013
Because you're essentially adding two images with the least significant bit of one zeroed out, you're most likely going to get overflow which, for a uint8 image, means that you'll clip at 288. Cast everything to double before summing to avoid the error.
  6 Comments
ROMIL
ROMIL on 26 Dec 2013
Well I can overwrite the existing plane, but still need to merge all the bit planes, can you provide me a better alternative to arithmetic sum?

Sign in to comment.

More Answers (0)

Categories

Find more on Encryption / Cryptography in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!