10-21-2011 01:14 AM
Hello,
I tried to convert this MATLAB imaging code with LabVIEW. I found error and I guess my labVIEW program is incomplete.
Can you check and extend your hand for help please!!!!!!!!!!!!!! Here is the full code and my incomplete program is also attached.
% now generate the image, MatLab code.
pixelspermm = 37;
imagedepth=14;
hei=round(pixelspermm*imagedepth);
wid=numAlines;
img=zeros(hei,wid);
for i=1:numAlines
% img(:,i)=resample(abs (compimg(i,1:imglen)).',wid,imglen);
img(:,i)=abs (compimg(i,1:hei)).';
end
tmp=sprintf('OCT image of depth % d mm',imagedepth);
figure; imshow(img,[]); title(tmp);
cd(curdir);
10-21-2011 04:22 AM
What error code and message does MathScript return?
10-24-2011 11:54 AM
Hello ssujann1,
This is Andrew Brown, an Applications Engineer from National Instruments. A quick look over your MATLAB code compared to your LabVIEW code shows some significant differences. Functions you may need to use include the IMAQ Resample VI, Array Subset VI, and a For loop.
Regards,
Andrew Brown
07-19-2012 08:39 AM
Hi Every1,
Here is Matlab code, i want implement it in mathscript node but its giving the problems, please help me......
clear all;
close all;
clc;
Imc=imread('C:\Users\electrono\Desktop\brain Tumer Project\Bijapur Project\11jun2012\Tumoured images\2.jpg');
imc=double(Imc(:,:,1));
figure(1),
imagesc(imc);colormap(gray);
[m,n]=size(imc)
c0=1;
initialLSF = c0*ones(size(imc));
% generate the initial region R0 as two rectangles
initialLSF(25:35,40:50)=-c0;
%initialLSF(25:35,40:50)=-c0;
phi_1=initialLSF;
phi=phi_1
phiq=phi;
s=find(phiq==-1)
phiq(s)=0;
A=im2bw(phiq);
%phiq=phi;
im1=double(imc);
bt=1000;
a1=0.01;
L=3;
B=im2bw(ones(L,L));
% timestep=1; % time step
% mu=0.2/timestep; % coefficient of the distance regularization term R(phi)
% iter_inner=5;
% iter_outer=200;
% lambda=5; % coefficient of the weighted length term L(phi)
% alfa=-3; % coefficient of the weighted area term A(phi)
% epsilon=1.5; % papramater that specifies the width of the DiracDelta function
%
% sigma=.8; % scale parameter in Gaussian kernel
% G=fspecial('gaussian',15,sigma); % Caussian kernel
% Img_smooth=conv2(imc,G,'same'); % smooth image by Gaussiin convolution
% [Ix,Iy]=gradient(Img_smooth);
% f=Ix.^2+Iy.^2;
% g=1./(1+f); % edge indicator function.
figure(2);
hold off;
imagesc(imc);
colormap(gray);
hold on;
contour(phi,[0,0],'y');pause,
phi1=(phi+1)/2;
phi2=(1-phi)/2;
AB1=imdilate(A,B);
AB2=imerode(A,B);
% E=AB1-AB2;
% hold on;
% contour(E,[0,0],'r');
n1=sum(phi1(:));
n2=sum(phi2(:));
im1p=im1.*phi1;
im1m=im1.*phi2;
c1=sum(sum(im1p))/n1;
c2=sum(sum(im1m))/n2;
u=c1*phi1 + c2*phi2;
Du=1;
for i=1:50,
i
uold=u;
[phi_x,phi_y]=gradient(phi);
s=sqrt(phi_x.^2 + phi_y.^2);
smallNumber=1e-10;
Nx=phi_x./(s+smallNumber); % add a small positive number to avoid division by zero
Ny=phi_y./(s+smallNumber);
% curvature=div(Nx,Ny);
[nxx,junk]=gradient(Nx);
[junk,nyy]=gradient(Ny);
curvature=nxx+nyy;
delphi=bt*curvature-(u-im1).*Du;
phi=phi+a1*delphi;
phi1=(phi+1)/2;
phi2=(1-phi)/2;
AB1=imdilate(A,B);
AB2=imerode(A,B);
E=AB1-AB2;
% hold on;
% contour(E,[0,0],'r');
n1=sum(phi1(:));
n2=sum(phi2(:));
im1p=im1.*phi1;
im1m=im1.*phi2;
c1=sum(sum(im1p))/n1;
c2=sum(sum(im1m))/n2;
unew=c1*phi1 + c2*phi2;
Du=unew-uold;
s1=find(phi>0);
s2=find(phi<0);
phi(s2)=1;
phi(s1)=-1;
V=(1+phi)/2;
D=im2bw(E) & im2bw(V);
A=AB2|D;
phi=2*A-1;
figure(2)
if mod(i,2)==0,hold on;
contour(phi,[0,0],'r');
pause,end;
end;
hold on;
contour(phi,[0,0],'b');
Thanks in advance..
07-19-2012 08:18 PM
Hi,
What error did you get?
I opened your attached VI and run the MathScript Node code with some trivial data. The error I got was from contour function. The contour function in MathScript can not accept line attribute as input. Therefore, you need to change line 9 from
contour(phi,[0,0],'y');pause,
to
contour(phi,[0,0]);pause,
Besides contour, I did not see any other errors.