merging 8 bit planes into single plane by combining the values of each bit into 8-bit value for each pixel

13 vues (au cours des 30 derniers jours)
I have two separate 8 bit planes(Images) and I want to align the value of each bit into a 8bit pixel value.for example I have '1' '0' '1' '0' '1' ' 0' '1' '0' as first values of each bit planes and these values should be aligned as 10101010 in one plane as its value of its first pixel.what function to be used to combine these 8 images to form single images with above condition.
  5 commentaires
Guillaume
Guillaume le 13 Fév 2019
Dileep reddy's code and comments moved here:
% clearing the output screen
clc;
% reading image's pixel in c
c = imread('apple.tif');
adjustc=imresize(c,[256,256]);
% storing image information in cd
cd = double(adjustc);
% extracting all bit one by one
% from 1st to 8th in variable
% from c1 to c8 respectively
c1 = mod(cd, 2);
c2 = mod(floor(cd/2), 2);
c3 = mod(floor(cd/4), 2);
c4 = mod(floor(cd/8), 2);
c5 = mod(floor(cd/16), 2);
c6 = mod(floor(cd/32), 2);
c7 = mod(floor(cd/64), 2);
c8 = mod(floor(cd/128), 2);
% combining image again to form equivalent to original grayscale image
cc = (2 * (2 * (2 * (2 * (2 * (2 * (2 * c8 + c7) + c6) + c5) + c4) + c3) + c2) + c1);
figure;
subplot(2, 5, 1);
imshow(adjustc);
title('Original Image');
% plotting binary image having extracted bit from 1st to 8th
% in subplot from 2nd to 9th
subplot(2,5,2);
%disp(c1);
% plotting original image in first subplot
imshow(c1);
title('bit plane 1');
subplot(2,5,3);
%disp(c2);
imshow(c2);
title('bit plane 2');
subplot(2,5,4);
%disp(c3);
imshow(c3);
title('bit plane 3');
subplot(2,5,5);
%disp(c4);
imshow(c4);
title('bit plane 4');
subplot(2,5,6);
%disp(c5);
imshow(c5);
title('bit plane 5');
subplot(2,5,7);
%disp(c6);
imshow(c6);
title('bit plane 6');
subplot(2,5,8);
%disp(c7);
imshow(c7);
title('bit plane 7');
subplot(2,5,9);
%disp(c8);
imshow(c8);
title('bit plane 8');
% plotting recombined image in 10th subplot
subplot(2, 5, 10);
imshow(uint8(cc));
title('Recombined Image');
I= imread('cameraman.tif');
X1 = edge(I,'canny',0.075);
X2 = edge(I,'canny',0.085);
X3 = edge(I,'canny',0.095);
X4 = edge(I,'canny',0.105);
X5 = edge(I,'canny',0.115);
X6 = edge(I,'canny',0.125);
X7 = edge(I,'canny',0.150);
X8 = edge(I,'canny',0.175);
figure;
subplot(2, 5, 1);
imshow(I);
title('Original Image');
subplot(2, 5, 2);
%disp(BX1);
imshow(X1);
title('Edge map 1');
subplot(2, 5, 3);
%disp(BX2);
imshow(X2);
title('Edge map 2');
subplot(2, 5, 4);
%disp(BX3);
imshow(X3);
title('Edge msp 3');
subplot(2, 5, 5);
%disp(BX4);
imshow(X4);
title('Edge map 4');
subplot(2, 5, 6);
%disp(BX5);
imshow(X5);
title('Edge map 5');
subplot(2, 5, 7);
%disp(BX6);
imshow(X6);
title('Edge map 6');
subplot(2, 5, 8);
%disp(BX7);
imshow(X7);
title('Edge map 7');
subplot(2, 5,9);
%disp(X8);
imshow(X8);
title('Edge map 8');
%xor operation for both the bit decompsed images and edge maps for all the
%8 bit planes
result1xor=bitxor(c1,X1);
result2xor=bitxor(c2,X2);
result3xor=bitxor(c3,X3);
result4xor=bitxor(c4,X4);
result5xor=bitxor(c5,X5);
result6xor=bitxor(c6,X6);
result7xor=bitxor(c7,X7);
result8xor=bitxor(c8,X8);
figure;
subplot(4,2,1);
imshow(result1xor);
%disp(result1xor);
title('1st bit Xor Image');
subplot(4,2,2);
imshow(result2xor);
%disp(result2xor);
title('2nd bitplane Xor ');
subplot(4,2,3);
imshow(result3xor);
%disp(result3xor);
title('3rd bitplane Xor ');
subplot(4,2,4);
imshow(result4xor);
%disp(result4xor);
title('4th bitplane Xor ');
subplot(4,2,5);
imshow(result5xor);
%disp(result5xor);
title('5th bitplane Xor ');
subplot(4,2,6);
imshow(result6xor);
%disp(result6xor);
title('6th bitplane Xor ');
subplot(4,2,7);
imshow(result7xor);
%disp(result7xor);
title('7th bitplane Xor ');
subplot(4,2,8);
imshow(result8xor);
disp(result8xor);
title('8th bitplane Xor ');
q1 = result1xor;
q2 = result2xor;
q3 = result3xor;
q4 = result4xor;
q5 = result5xor;
q6 = result6xor;
q7 = result7xor;
q8 = result8xor;
This is my code .At last I want to combine q1,q2...q8 into one image with the previous condition mentioned.
If i use imfuse() function for will it satisfy above condition

Connectez-vous pour commenter.

Réponse acceptée

Guillaume
Guillaume le 13 Fév 2019
No, imfuse will not work. imfuse has no concept of bits.
Your question is actually very puzzling. You already know how to combine the bits together, you've already done it earlier in your code:
% combining image again to form equivalent to original grayscale image
cc = (2 * (2 * (2 * (2 * (2 * (2 * (2 * c8 + c7) + c6) + c5) + c4) + c3) + c2) + c1);
It's certainly not efficient, but it does the job.
With regards to your code, the first thing you need to do is to stop numbering variables, which forces you to write the same code 8 times. You should let the computer do that repetitive job for you by using the mechanism that matlab has for numbering things: the index of matrices of cell array. Then you can use for loops to do the repetition. E.g.:
c = imread('apple.tif'); %an using variable names that have meaning would be a good idea too
adjustc=imresize(c,[256,256]);
cd = double(adjustc);
bitmages = cell(1, 8);
%or even better would be a 3D matrix:
%bitimages = zeros(256, 256, 8]);
for bit = 1:8
bitimages{bit} = mod(floor(cd/2^(bit-1), 2)); %or simply bitimages{bit} = bitget(cd, bit);
%if using 3d matrix
%bitimages(:, :, bit) = bitget(cd, bit);
end
%plotting each image:
for bit = 1:8
subplot(2, 5, bit+1);
imshow(bitimages{bit}); %or imshow(bitimages(:, :, bit)) if using 3d matrix
title(sprintf('bit plane %d', bit));
end
%... loading of cameraman
%computation of the X
X = cell(1, 8);
for bit = 1:8
X{i} = edge('I, 'canny', 0.065 + bit * 0.01);
end
%plotting of the X
for bit = 1:8
subplot(2, 5}, bit + 1);
imshow(X{bit});
title(sprintf('Edge map %d', bit);
end
Isn't this simpler?
Note that the way you're storing the bits is very innefficient. You start with each bit stored as actual bits of an 8-bit integer (uint8). So each pixel takes 1 bytes. You then convert the pixels to double, so each pixel takes 8 bytes. You then store each bit of each pixel as double, so each bit takes 8 bytes and a pixel now uses 64 bytes of memory. Your original 256x256 image which used to occupy 65,536 bytes now occupy 4,194,304 bytes of memory to store exactly the same information. There's no need for that, you could actually manipulate the bits of your original uint8 array directly (with bitget, bitset and all the bitxxx functions).
Also, note that your bitxor is not truly a bitxor It does the job you want but conceptually you're misusing it here. You're truly doing a logical xor instead. The result is the same because the values you store in the array are just 0 and 1 (and aso because matlab assumes that the double values represent integers).
  4 commentaires
DILEEP REDDY
DILEEP REDDY le 13 Fév 2019
This is the concept of what I am doing.for 4th step I need to obtain a single Image with first pixel value of linear combination of each pixel value of Individual xor images .IMG_20190213_191936__01.jpg
Guillaume
Guillaume le 13 Fév 2019
Modifié(e) : Guillaume le 13 Fév 2019
I understood what you're doing from the code the first time round. I'm not sure why you're restating it, and I'm not sure what problem you have any more. As I said, you can use the same recombination method.
If you're still using numbered variables (don't!), then:
finalimage = (2 * (2 * (2 * (2 * (2 * (2 * (2 * q8 + q7) + q6) + q5) + q4) + q3) + q2) + q1);
If you're using indexing, you'd use either a loop:
finalimage = zeros(size(q{1})); %if using cell arrays, finalimage = zeros(size(q, 1), size(q, 2)) %if using 3d array
for bit = 1:8
finalimage = finalimage + q * 2^(bit-1);
end
Or the vectorised way
finalimage = sum(cat(3, q{:}) .* 2.^[0:7], 3); %if q is a cell array
finalimage = sum(q .* 2.^[0:7], 3); %if q is a 3d matrix

Connectez-vous pour commenter.

Plus de réponses (1)

Walter Roberson
Walter Roberson le 12 Fév 2019
Since your data appears to be char, then permute it so that all of the bits for a pixel are across the rows, and then use bin2dec(), followed by reshape() into the appropriate array size.
  2 commentaires
DILEEP REDDY
DILEEP REDDY le 12 Fév 2019
This is what I did. First I took one 8bit image and then used bit decomposition to produce 8images(binary bit planes). and then I took another 8bit image and used canny edge detection with varying thresholds to produce 8 edgemaps(binary) Now I xored first 8 bit decomposed images with 8 edge maps.I got 8 xored images.Now I want to combine these images such that the first bits of these images form a 8bits which is the value of fisrt pixel in combined Image.Like that the pixel values should become or combined to become 8bit value of New image pixel.Plz help
James Tursa
James Tursa le 12 Fév 2019
Can you please help us out and show us the actual variable class and sizes involved, and show us the current code you are using?

Connectez-vous pour commenter.

Catégories

En savoir plus sur End-to-End Simulation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by