convert double into unit8 with out changing pixel's value

3 views (last 30 days)
i want to change my image matrix which double type into uint8 type value so i can subtract another matrix which is uint8 type my code is
clc;
clear;
rgb = imread('flower.jpg');
rgb = imresize(rgb,[256,256]);
mlab = makecform('srgb2lab');
lab = applycform(rgb,mlab);
S_bin = im2bw(rgb);
S = S_bin + (S_bin == 0);
NS=S;
%[a,b,c] = size(lab);
L=lab(:,:,1);%figure(1);imshow(L);
A=lab(:,:,2);%figure(2);imshow(A);
B=lab(:,:,3);%figure(3);imshow(B);
k=1;
for i=1:256
for j=1:256
% disp(i);
% disp(j);
m = region(i,j,lab);
A1=m(:,:,2);
B1=m(:,:,3);
Amean = mean2(A1);
Bmean = mean2(B1);
L1=m(:,:,1);
Lmean = mean2(L1);
Lstd = std(L1);
if Amean+Bmean<=256
if L <= (Lmean - (Lstd/3))
S(j,i,1)=0;
S(j,i,2)=0;
S(j,i,3)=0;
else
S(j,i,1)=L1;
S(j,i,2)=A1;
S(j,i,3)=B1;
end
else
if L(i,j) < B(i,j)
S(j,i,1)=0;
S(j,i,2)=A1;
S(j,i,3)=B1;
elseif B(i,j) < L(i,j)
S(j,i,1)=L1;
S(j,i,2)=A1;
S(j,i,3)=0;
else
S(j,i,1)=L1;
S(j,i,2)=A1;
S(j,i,3)=B1;
end
end
if(j==255)
break;
end
end;
if(i==255)
break;
end
end;
S1 = uint8(S);
sub = imsubtract(rgb,S2);
imshow(sub);
in above code rgb(type 256*256*3 uint8) is main image, S(type 256*256*3 double) is a image which is output image after doing some pixel operation now for subtracting image i have to convert one of them ,and make both of them same type image so i convert S into S1 but at here it changes pixel value of image which is affecting to main output so please ,give me solution to convert one of them and make both image as equal type but it should not change its value
  2 Comments
Image Analyst
Image Analyst on 17 Aug 2015
What is this code supposed to do? I've never seen anybody compare an L value to an A or a B value! What's up with that???? Also, what is S supposed to be? What does the region() function do?
hardik mehta
hardik mehta on 17 Aug 2015
I am sorry for trouble sir,but my problem had been solved and thank you for you time. actually above problem is for detecting shadow from image . in that i had separated shadow pixel into another image and that image i want to subtract from original image .

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 17 Aug 2015
double() the uint8 image instead of uint8() the double image.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!