I have an image and separated it into R G B planes.next i have applied bit plane slicing to each planes. now i want to convert the bit plane sliced images to bitmap images(in 1's and -1's form),i have written following code.but it displays black img

4 Ansichten (letzte 30 Tage)
%this is the code:
clear all;
clc;
close all;
a=imread('F:\iris_db\1.png');
R=a;
G=a;
B=a;
R(:,:,2)=0;
R(:,:,3)=0;
G(:,:,1)=0;
G(:,:,3)=0;
B(:,:,1)=0;
B(:,:,2)=0;
imwrite(R,'F:\second year\output imgs\1stplane.png');
imwrite(G,'F:\second year\output imgs\2ndplane.png');
imwrite(B,'F:\second year\output imgs\3rdplane.png');
%%apply bit plane slicing on R plane
R=double(R);
rp1=bitget(R,1);
rp2=bitget(R,2);
rp3=bitget(R,3);
rp4=bitget(R,4);
rp5=bitget(R,5);
rp6=bitget(R,6);
rp7=bitget(R,7);
rp8=bitget(R,8);
imwrite(rp1,'F:\second year\output imgs\rp1.png');
imwrite(rp2,'F:\second year\output imgs\rp2.png');
imwrite(rp3,'F:\second year\output imgs\rp3.png');
imwrite(rp4,'F:\second year\output imgs\rp4.png');
imwrite(rp5,'F:\second year\output imgs\rp5.png');
imwrite(rp6,'F:\second year\output imgs\rp6.png');
imwrite(rp7,'F:\second year\output imgs\rp7.png');
imwrite(rp8,'F:\second year\output imgs\rp8.png');
% apply bit plane slicing on G plane
G=double(G);
gp1=bitget(G,1);
gp2=bitget(G,2);
gp3=bitget(G,3);
gp4=bitget(G,4);
gp5=bitget(G,5);
gp6=bitget(G,6);
gp7=bitget(G,7);
gp8=bitget(G,8);
imwrite(gp1,'F:\second year\output imgs\gp1.png');
imwrite(gp2,'F:\second year\output imgs\gp2.png');
imwrite(gp3,'F:\second year\output imgs\gp3.png');
imwrite(gp4,'F:\second year\output imgs\gp4.png');
imwrite(gp5,'F:\second year\output imgs\gp5.png');
imwrite(gp6,'F:\second year\output imgs\gp6.png');
imwrite(gp7,'F:\second year\output imgs\gp7.png');
imwrite(gp8,'F:\second year\output imgs\gp8.png');
% apply bit plane slicing on B plane
B=double(B);
bp1=bitget(B,1);
bp2=bitget(B,2);
bp3=bitget(B,3);
bp4=bitget(B,4);
bp5=bitget(B,5);
bp6=bitget(B,6);
bp7=bitget(B,7);
bp8=bitget(B,8);
imwrite(bp1,'F:\second year\output imgs\bp1.png');
imwrite(bp2,'F:\second year\output imgs\bp2.png');
imwrite(bp3,'F:\second year\output imgs\bp3.png');
imwrite(bp4,'F:\second year\output imgs\bp4.png');
imwrite(bp5,'F:\second year\output imgs\bp5.png');
imwrite(bp6,'F:\second year\output imgs\bp6.png');
imwrite(bp7,'F:\second year\output imgs\bp7.png');
imwrite(bp8,'F:\second year\output imgs\bp8.png');
now generate binary bitmap of the plane images. convert into 1's and
%%-1's format. read a bit, if it is 1 then keep it as it is else make it %%-1
[d1,d2,d3]= size(a);
%
for i=1:d1 %d1=576
for j=1:d2 %d2=768
%for rp1
if rp1(i,j)==1
rp1(i,j)=1;
else
rp1(i,j)=-1;
end
if rp2(i,j)==1
rp2(i,j)=1;
else
rp2(i,j)=-1;
end
if rp3(i,j)==1
rp3(i,j)=1;
else
rp3(i,j)=-1;
end
if rp4(i,j)==1
rp4(i,j)=1;
else
rp4(i,j)=-1;
end
if rp5(i,j)==1
rp5(i,j)=1;
else
rp5(i,j)=-1;
end
if rp6(i,j)==1
rp6(i,j)=1;
else
rp6(i,j)=-1;
end
if rp7(i,j)==1
rp7(i,j)=1;
else
rp7(i,j)=-1;
end
if rp8(i,j)==1
rp8(i,j)=1;
else
rp8(i,j)=-1;
end
end
end
imshow(rp8);
impixelinfo;
[EDITED, Jan, Please format your code - Thanks]

Antworten (1)

Jan
Jan am 17 Okt. 2013
This is meaningless:
if rp1(i,j)==1
rp1(i,j)=1;
...
An easier and faster method to replace 0 by -1 without two loops:
rp1(rp1==0) = -1;
A "binary" format with -1 instead of zeros is rather unusual. I do not assume that Matlab supports this strange format.
Better stay at the zeros. Perhaps this helps:
rp8 = uint8(rp8);
imshow(rp8);
Or:
img8 = ind2rgb(rp8, [0,0,0; 0,1,0]);
imshow(img8);
  2 Kommentare
Pushpa Mandal
Pushpa Mandal am 17 Okt. 2013
I still dint get the correct output.Actually i want to generate a bitmap of the image(in 1's and -1' s form). but its not working correctly.I am getting same image as output. I want it to be in 1's and -1's form.please help.
Pushpa Mandal
Pushpa Mandal am 17 Okt. 2013
I still dint get the correct output.Actually i want to generate a bitmap of the image(in 1's and -1' s form). but its not working correctly.I am getting same image as output. I want it to be in 1's and -1's form.please help.
%%rp8 = uint8(rp8); %%imshow(rp8);
this is displaying black image.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by