In code1 a delaunay triangulated mesh is generated. In code2 instead of image i want to process the mesh that is generated in code1. is it possible? I want to convert the mesh into an image
Show older comments
*CODE 1:*
a=imread('IMD003.bmp');
%imshow(a)
se = strel('disk',11);
rgbImage=imclose(a,se);
ID = im2double(rgbImage);
%imshow(I);
%ex = edge(ID,'canny');
[h, w] = size(ID);
filter = [0.0174 0.348 0.04348 0.0348 0.0174; 0.0348 0.0782 0.1043 0.0782 0.0348; 0.0435 0.1043 0.1304 0.1043 0.0435;0.0348 0.0782 0.1043 0.0782 0.0348; 0.0174 0.348 0.04348 0.0348 0.0174];
Mx = [-1 0 1; -2 0 2; -1 0 1];
My = [-1 -2 -1; 0 0 0; 1 2 1];
for v = 2 : 511
for u = 2 : 511
sum = 0;
for i = -2 : 2
for j = -2 : 2
sum = sum + (ID(u, v) * filter(i+3, j+3));
end
end
IDx(u,v) = sum;
end
end
%APPLYING SOBEL MASK ON X-DIRECTION
for v = 2:510
for u = 2:510
sum1 = 0;
for i=-1:1
for j=-1:1
sum1 = sum1 + IDx(u + i, v + j)* Mx(i + 2,j + 2);
end
end
IDxx(u,v) = sum1;
end;
end
%APPLYING SOBEL MASK ON Y-DIRECTION
for v = 2:510
for u = 2:510
sum2 = 0;
for i=-1:1
for j=-1:1
sum2 = sum2 + IDx(u + i, v + j)* My(i + 2,j + 2);
end
end
IDyy(u,v) = sum2;
end;
end
for v = 2:510
for u = 2:510
mod(u,v) = abs(IDxx(u,v)) + abs(IDyy(u,v));
end
end
supimg(u,v) = 0;
for v = 2 : 509
for u = 2 : 509
theta(u,v) = abs(atand(IDyy(u,v)/IDxx(u,v)));
if ((theta(u,v) >= 0) && (theta(u,v) <= 22.5) || (theta(u,v) >= 157.5) && (theta(u,v) <= 180))
ntheta(u,v) = 0;
end;
if ((theta(u,v) >= 22.5) && (theta(u,v) <= 67.5))
ntheta(u,v) = 45;
end;
if ((theta(u,v) >= 67.5) && (theta(u,v) <= 112.5))
ntheta(u,v) = 90;
end;
if ((theta(u,v) >= 112.5) && (theta(u,v) <= 180))
ntheta(u,v) = 135;
end;
% N O N - M A X I M U M S U P P R E S S I O N
if (ntheta(u,v) == 0)
if (mod(u, v) < mod(u-1, v) || mod(u, v) < mod(u+1, v))
supimg(u,v) = 0;
else supimg(u,v)= mod(u,v);
end;
end;
if (ntheta(u,v) == 45)
if (mod(u, v) < mod(u+1, v-1) || mod(u, v) < mod(u-1, v+1))
supimg(u,v) = 0;
else supimg(u,v)= mod(u,v);
end;
end;
if (ntheta(u,v) == 90)
if (mod(u, v) < mod(u, v-1) || mod(u, v) < mod(u, v+1))
supimg(u,v) = 0;
else supimg(u,v)= mod(u,v);
end;
end;
if (ntheta(u,v) == 135)
if (mod(u, v) < mod(u-1, v-1) || mod(u, v) < mod(u+1, v+1))
supimg(u,v) = 0;
else supimg(u,v) = mod(u,v);%Supimg -- Image obtained after Non-mSupression
end ;
end;
% E N D O F N O N - M A X I M U M S U P P R E S S I O N
end
end
%T H R E S H O L D I N G
th =2.0; %8.0; %High Threshhold
%th = max(supimg);
tl = 0.03; %th/6; %Low Threshhold
gnh(u,v) = 0;
gnl(u,v) = 0;
for v = 2 : 509
for u = 2 : 509
if(supimg(u,v) >= th)
gnh(u,v) = supimg(u,v);
end
if(supimg(u,v) >= tl)
gnl(u,v) = supimg(u,v);
end
end
end
% E N D OF T H R E S H O L D I N G
resimg = gnl - gnh; %Edge of the Image
%subplot (1, 2, 1),imshow(ID);axis image; title('Original Image');
%subplot (1, 2, 2),imshow(resimg);axis image; title('Canny Edge Image');
%subplot (2, 3, 1),imshow(ID);axis image; title('Original Image');
%subplot (2, 3, 2),imshow(IDx);axis image; title('Filtered Image');
%subplot (2, 3, 3),imshow(IDxx);axis image; title('X- Direction Image');
%subplot (2, 3, 4),imshow(IDyy);axis image; title('Y- Direction Image');
%subplot (2, 3, 5),imshow(supimg);axis image; title('Non-Max Suppress');
imshow(resimg);axis image; title('Canny Edge');
imshow(resimg);
I = bwmorph(resimg,'skel',Inf);
[i1,j1] = ind2sub(size(I),find(bwmorph(bwmorph(I,'thin',Inf),'branchpoint') == 1));
tri1 = delaunayTriangulation(i1,j1)
figure
triplot(tri1)
*CODE 2*
%%%%%%%%%%%%%%%%%%%%Pre-processing step%%%%%%%%%%%%%%%
open=1;
a=imread('IMD009.bmp');
imshow(a)
se = strel('disk',11);
rgbImage=imclose(a,se);
Im = im2double(rgbImage);
%Im = imread('CANNY.bmp');
if length(size(Im))==3
%colour transform into NTSC coulour space allowing us to work on the
%intensity channel
Im=rgb2ntsc(Im);
end
I2=im2uint8(Im(:,:,1));
Store=I2;
if open==1
se=strel('square',4);
I2=imopen(I2,se);
end
if flag==1
I2=imcomplement(I2);
end
EdHist=1;
if EdHist==1
I2=histeq(medfilt2(I2));
end
Orig=I2;
%%%%%%%%%%%%%%%%%%%%Getting segmentation values%%%%%%%%%%%%%%%
[x xx]=imhist(I2);
C=[x,xx];
%%%%%%
k=convhull(C(:,1),C(:,2));
X_conv=C(k,1);
Y_conv=C(k,2);
Maxim_C=max(C(:,1));
Max_Conv=max(X_conv(:,1));
%Getting the 1st maxima
[Point,m]=find(X_conv==Max_Conv);
Point_1=Y_conv(Point,1);
X_conv(Point,1)=0;
Max_Conv=max(X_conv(:,1));
%Getting the 2nd maxima
[Point,m]=find(X_conv==Max_Conv);
Point_2=Y_conv(Point);
C(1:min(Point_1,Point_2),1)=Maxim_C;
C(max(Point_1,Point_2):256,1)=Maxim_C;
C(:,1)=sqrt((C(:,1)-Maxim_C).^2);
Temp_C=C(k,2);
Temp_C=sort(Temp_C);
%%%%%%%%
%T=C(:,1);
f=convhull(C(:,1),C(:,2));
Arr=C(f,2);
Arr2=C(f,1);
[count,no]=find(C(f,1)~=0);
Array=Arr(count);
%%%%%%%%%%%%
Temp=C(f,1);
Temp2=C(f,2);
cell1=0;
cell2=0;
for i=1:length(Temp)
if Temp(i,1)~=0
cell1=Temp(i,1);
i=length(Temp);
end
end
for i=length(Temp):-1:1
if Temp(i,1)~=0
cell2=Temp(i,1);
i=1;
end
end
Max_C=max(C(:,1));
if (cell1>0 && cell2>0)
Point_New=find(C(:,1)==cell1);
Point_New=Point_New(1);
Point_New2=find(C(:,1)==cell2);
Point_New2=Point_New2(end);
C(1:Point_New,1)=Max_C;
C(Point_New2:length(C(:,1)),1)=Max_C;
C=C(1:256,:);
C(:,1)=sqrt((C(:,1)-Maxim_C).^2);
end
Array=[Array;Temp_C];
Array=sort(Array);
for i=1:length(Array(:))-1
if Array(i)==Array(i+1)
Array(i+1)=0;
end
end
Array=sort(Array);
[D,n]=(find(Array>0));
Array=Array(D);
Orig(Orig<Array(1,1))=0;
Orig(Orig>Array(length(Array(:)),1))=0;
d=[];
%%%%%%%%%%%%%%%%%%%%Segmentation of the image%%%%%%%%%%%%%%%
for i=1:length(Array(:))-1
if i==1
Orig(Orig>=Array(i) & Orig<=Array(i+1))=Array(i+1);
d=[d;Array(i+1)];
else
Orig(Orig>Array(i) & Orig<=Array(i+1))=Array(i+1);
d=[d;Array(i+1)];
end
end
d=sort(d);
Orig_Color=[];
if length(size(Im))==3
Im(:,:,1)=im2double(Orig);
Orig_Color=ntsc2rgb(Im);
[x xx]=imhist(im2uint8(Im(:,:,1)));
Array=xx(x>0);
else
[x xx]=imhist(im2uint8(Orig(:,:,1)));% Corrected!
Array=xx(x>0);
end
Segmented=im2uint8(Orig);
%Time=toc;
% Calculating additional info, i.e., comparision of the number of
% grayvalues before and after the segmentation
[x xx]=imhist(Store);
Count=xx(xx>0);
%%%%Display the segmented regions as binary
%if length(size(Segmented))==3
%Segmented=rgb2ntsc(Segmented);
%end
% Segmented=im2double(Segmented(:,:,1));
% [n nn]=hist(Segmented);
% for i=1:length(nn)
% if i=1
% figure, imshow(A(:,:,1)<=nn(i),[])
% else
% figure, imshow(A(:,:,1)<=nn(i) & A(:,:,1)>nn(i-1),[])
% end
% end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure, imshow(Segmented), title(sprintf('Delaunay based unsupervised segmentation'))
if ~isempty(Orig_Color)
figure, imshow(Orig_Color),title(sprintf('Color Delaunay based unsupervised segmentation'));
imwrite(Orig_Color,'Segmented_Color.tif')
end
1 Comment
KSSV
on 6 Apr 2018
To convert mesh into image....save the figure into image format using saveas
Answers (0)
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!