如何使用 MATLAB 将静脉保留为黑色?
我有这张红外图像,它捕捉到了皮肤下的静脉。我想处理这张图像,以便仅保留静脉为黑色,而将其他所有内容保留为白色。然后我想生成坐标像素作为这些黑色像素,它们将是静脉。
这就是我到目前为止所做的:
a=imread('11.jpg');
figure(1),imshow(a);
title('original image');
cform = makecform('srgb2lab');
for ii = 1:3
a(:,:,ii) = medfilt2(a(:,:,ii),[5 5]);
end
lab = applycform(a,cform);
figure(2),imshow(lab);
title('ímage in color space after filtering');
b=lab(:,:,1);
c=im2bw(b,0.2);
figure(3),imshow(c);
title('b&white boundry of fist');
neg=1-c;
figure(4),imshow(neg);
color=a;
r=color(:,:,1);
r(~c)= 0;
g = color(:,:,2);
g(~c)= 0;
b = color(:,:,3);
b(~c)= 0;
% Concatenate in the "3rd dimension" to re-constitute an RGB image.
color = cat(3,r,g,b);
figure(5),
imshow(color);
title('reconstructed fist with black bg');
gray=rgb2gray(color);
figure(6);
imshow(gray);
title('grayscale of fist');
i1=imresize(gray,[256 256],'bilinear');
figure(7);
imshow(i1);
title('Resized Image of grayscale');
figure(8),imhist(i1);
title('histogram of resized grayscale');
i2=histeq(i1,256);
figure(9),imshow(i2);
title('histogram equalisatio');
figure(10),imhist(i2);
title('équalised histogram');
e=medfilt2(i2,[5 5]);
figure(7),imshow(e);
f=medfilt2(e,[5 5]);
figure(8),imshow(f);
g=medfilt2(f,[5 5]);
figure(9),imshow(g);
s=g;
figure(10),imshow(s);
l=imresize(s,[200 200]);
figure(11);
imshow(l);
[h,u]=size(l);
smth=double(l);
wl=1.5;
we=3;
wt=15;
eline=smth;;
[grady,gradx]=gradient(smth);
eedge=-1*sqrt((gradx.*gradx+grady.*grady));
figure(12);
imshow(uint8(-eedge));
m1=[-1 1];
m2=[-1;1];
m3=[1 -2 1];
m4=[1;-2;1];
m5=[1 -1;-1 1];
cx=conv2(smth,m1,'same');
cy=conv2(smth,m2,'same');
cxx=conv2(smth,m3,'same');
cyy=conv2(smth,m4,'same');
cxy=conv2(smth,m5,'same');
for i=1:h
for j=1:u
eterm(i,j)=(cyy(i,j)*cx(i,j)*cx(i,j)-2*cxy(i,j)*cx(i,j)*cy(i,j)+cxx(i,j)*cy(i,j)*cy(i,j))/((1+cx(i,j)*cx(i,j)+cy(i,j)*cy(i,j))^1.5);
end
end
figure(13);
imshow(uint8(-eterm));
eext=(wl*eline+we*eedge+wt*eterm);
figure(14);
imshow(uint8(eext));
eext=(wl*eline+we*eedge);
figure(15);
imshow(uint8(eext));
whos eext;
这是图像:
那么在此之后我该如何继续这样我就可以将静脉保留为黑色,其他所有部分保留为白色?
这是中值滤波后的图像,您可以看到静脉非常暗。那么我该如何从这里开始,使静脉保留为黑色,而其他一切保留为白色呢?
I have this Ir image that has captured the veins under the skin. I want to process this image so as to retain just the veins as black colour and get everything else as white. Then I want to generate the coordinate pixels as these black pixels which will be the veins.
This is what I have done till now :
a=imread('11.jpg');
figure(1),imshow(a);
title('original image');
cform = makecform('srgb2lab');
for ii = 1:3
a(:,:,ii) = medfilt2(a(:,:,ii),[5 5]);
end
lab = applycform(a,cform);
figure(2),imshow(lab);
title('ímage in color space after filtering');
b=lab(:,:,1);
c=im2bw(b,0.2);
figure(3),imshow(c);
title('b&white boundry of fist');
neg=1-c;
figure(4),imshow(neg);
color=a;
r=color(:,:,1);
r(~c)= 0;
g = color(:,:,2);
g(~c)= 0;
b = color(:,:,3);
b(~c)= 0;
% Concatenate in the "3rd dimension" to re-constitute an RGB image.
color = cat(3,r,g,b);
figure(5),
imshow(color);
title('reconstructed fist with black bg');
gray=rgb2gray(color);
figure(6);
imshow(gray);
title('grayscale of fist');
i1=imresize(gray,[256 256],'bilinear');
figure(7);
imshow(i1);
title('Resized Image of grayscale');
figure(8),imhist(i1);
title('histogram of resized grayscale');
i2=histeq(i1,256);
figure(9),imshow(i2);
title('histogram equalisatio');
figure(10),imhist(i2);
title('équalised histogram');
e=medfilt2(i2,[5 5]);
figure(7),imshow(e);
f=medfilt2(e,[5 5]);
figure(8),imshow(f);
g=medfilt2(f,[5 5]);
figure(9),imshow(g);
s=g;
figure(10),imshow(s);
l=imresize(s,[200 200]);
figure(11);
imshow(l);
[h,u]=size(l);
smth=double(l);
wl=1.5;
we=3;
wt=15;
eline=smth;;
[grady,gradx]=gradient(smth);
eedge=-1*sqrt((gradx.*gradx+grady.*grady));
figure(12);
imshow(uint8(-eedge));
m1=[-1 1];
m2=[-1;1];
m3=[1 -2 1];
m4=[1;-2;1];
m5=[1 -1;-1 1];
cx=conv2(smth,m1,'same');
cy=conv2(smth,m2,'same');
cxx=conv2(smth,m3,'same');
cyy=conv2(smth,m4,'same');
cxy=conv2(smth,m5,'same');
for i=1:h
for j=1:u
eterm(i,j)=(cyy(i,j)*cx(i,j)*cx(i,j)-2*cxy(i,j)*cx(i,j)*cy(i,j)+cxx(i,j)*cy(i,j)*cy(i,j))/((1+cx(i,j)*cx(i,j)+cy(i,j)*cy(i,j))^1.5);
end
end
figure(13);
imshow(uint8(-eterm));
eext=(wl*eline+we*eedge+wt*eterm);
figure(14);
imshow(uint8(eext));
eext=(wl*eline+we*eedge);
figure(15);
imshow(uint8(eext));
whos eext;
and this is the image:
So how do I proceed after this so that I retain the veins as black and eveything else as white?
So this is the image after median filtering, as you can see the veins are quite dark. So how do I proceed from here so that the veins are retained as black and everything else as white?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
获得第二张图像后,您需要对其进行图像阈值以得到你所要求的。您可以自己实现它或使用 matlab 中的 graythresh (需要图像处理工具箱)。
Once you have the second image, you will need to do image thresholding on it to get what you are asking for. You can implement it yourself or use graythresh from matlab (requires image processing toolbox).