如何使用 MATLAB 将静脉保留为黑色?

发布于 2024-11-03 06:37:03 字数 2312 浏览 1 评论 0原文

我有这张红外图像,它捕捉到了皮肤下的静脉。我想处理这张图像,以便仅保留静脉为黑色,而将其他所有内容保留为白色。然后我想生成坐标像素作为这些黑色像素,它们将是静脉。

这就是我到目前为止所做的:

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:

enter image description here

So how do I proceed after this so that I retain the veins as black and eveything else as white?

after median filtering

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

执手闯天涯 2024-11-10 06:37:03

获得第二张图像后,您需要对其进行图像阈值以得到你所要求的。您可以自己实现它或使用 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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文