convert double into unit8 with out changing pixel's value
3 views (last 30 days)
Show older comments
hardik mehta
on 17 Aug 2015
Commented: hardik mehta
on 17 Aug 2015
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
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?
Accepted Answer
Walter Roberson
on 17 Aug 2015
double() the uint8 image instead of uint8() the double image.
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!