Eclipse Run Display Different Every time - eclipse

I'm getting real pissed because of a problem that I know for a fact that isn't on my end! Every time I run my current project in Eclipse, the display is different every time!
I mean, I run it once and it shows only three of my components.
I run it again and it shows more.
I run it again and it shows three
etc..
What the hell is going on. This is the code I'm running in a main string args:
JFrame frame = new JFrame("Survey");
frame.setSize(500, 500);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel(new GridBagLayout());
panel.setBackground(Color.GRAY);
frame.add(panel, BorderLayout.NORTH);
GridBagConstraints c = new GridBagConstraints();
JLabel label1 = new JLabel("First name:");
c.gridx = 0;
c.gridy = 0;
c.insets = new Insets(5, 5, 5, 5);
panel.add(label1, c);
JLabel label2 = new JLabel("Last name:");
c.gridx = 0;
c.gridy = 1;
panel.add(label2, c);
JTextField text1 = new JTextField(10);
c.gridx = 1;
c.gridy = 0;
panel.add(text1, c);
JTextField text2 = new JTextField(10);
c.gridx = 1;
c.gridy = 1;
panel.add(text2, c);
JLabel label3 = new JLabel("What is your favorite sport:");
c.gridx = 0;
c.gridy = 2;
c.gridwidth = 2;
panel.add(label3, c);
String[] combobox = {"Basketball", "Soccor", "Other"};
JComboBox cbx = new JComboBox(combobox);
cbx.setPreferredSize(new Dimension(150, 20));
c.gridx = 0;
c.gridy = 3;
panel.add(cbx, c);
JLabel label4 = new JLabel("Comments about yourself:");
c.gridx = 0;
c.gridy = 4;
panel.add(label4, c);
JTextArea area = new JTextArea();
area.setPreferredSize(new Dimension(185, 100));
c.gridx = 0;
c.gridy = 5;
c.gridheight = 5;
panel.add(area, c);
JButton submit = new JButton("Submit");
submit.setPreferredSize(new Dimension(20, 20));
c.gridx = 0;
c.gridy = 6;
panel.add(submit, c);

Revalidate is not needed at all. Make sure you properly create your components on EDT thread and you'll have no such problems anymore. Check out the following article http://docs.oracle.com/javase/tutorial/uiswing/concurrency/initial.html

Related

How to create object within function MatLab without creating a new file

I am working on a project with the following specs:
https://drive.google.com/file/d/14xaCK-1Mpd8FXM-19pfFC1UTk2V9oXkQ/view?usp=sharing
My code is attached below.
How do I get my final output as a data object and info object like they are asking, without creating a new class file? The format required is in the picture below.
Final format required:
function [data,info] = OneNormLPxxx(A,b)
%L1 norm minimization for a given A and b.
% Detailed explanation goes here
count = 0;
b_vect = b;
[m,n] = size(A);
max_count = 3*nchoosek(m,n);
set_B = 1:n;
M = inv(A(set_B, :));
is_opt = 0;
while (is_opt == 0)
if (det(A(set_B,:)) == 0)
info = untitled4;
info.run = "Failure";
info.msg = "Degeneracy Problem";
data = untitled3;
return
end
if (max_count <= count)
info = untitled4;
info.run = "Failure";
info.msg = "Arithmetic Problem";
data = untitled3;
return
end
set_B_Comp = setdiff(1:m,set_B);
x_temp = M*b_vect(set_B);
h = A*x_temp - b_vect;
h(set_B_Comp) = A(set_B_Comp,:)*x_temp - b_vect(set_B_Comp);
y_vect = zeros(m, 1);
y_vect(set_B_Comp) = sign(h(set_B_Comp));
y_vect(set_B) = -(M')*((A(set_B_Comp,:)')*y_vect(set_B_Comp));
abs_y_B = abs(y_vect(set_B));
if all(abs_y_B <= 1)
is_opt = 1;
x_opt = x_temp;
opt_val = sum(abs(A*x_opt - b_vect));
data = untitled3;
data.obj = opt_val;
data.x = x_opt;
data.loop = count;
info = untitled4;
info.run = "Success";
return
% return B and x
else
all_index_y_vect_more_than_1 = find(abs(y_vect(set_B)) > 1);
s = all_index_y_vect_more_than_1(1);
y_s = y_vect(s);
t_vect = zeros(m, 1);
t_vect(set_B_Comp) = -(sign(y_s))*(y_vect(set_B_Comp)).*(A(set_B_Comp,:)*M(:,s));
cur_min = abs(h(set_B_Comp(1)))/t_vect(set_B_Comp(1)) + 1;
cur_r = set_B_Comp(1);
for j = set_B_Comp
h_j = h(j);
t_j = t_vect(j);
temp1 = abs(h_j)/t_j;
if (temp1 < cur_min) && (temp1 > 0) && (t_j > 0)
cur_min = temp1;
cur_r = j;
end
end
r = cur_r;
j_s = set_B(s);
set_B_new = setdiff(union(set_B, r), j_s);
set_B = set_B_new;
set_B_Comp = setdiff(1:m,set_B);
theta = (A(r,:)*M)';
M(:,s) = (1/theta(s))*M(:,s);
for j = 1:n
if (j ~= s)
M(:,j) = M(:,j) - theta(j)*M(:,s);
end
end
end
count = count + 1;
end
end
Rather than using
info = untitled4;
Use
info = struct();
This will create a MATLAB structure for storing your data.

In my code error is Index Exceeds Matrix Dimension

my code gives an error and that is Index exceeds matrix dimensions.It runs perfectly for nsample=10 but when I use nsamples=other value it gives error.
The error starts from line 108 that means when dataright(1:20) =
output(1:20);but it runs when I used dataright(1:10) = output(1:10).
function icall(block)
setup(block);
function setup(block)
block.NumInputPorts = 0;
block.NumOutputPorts = 4;
block.OutputPort(1).SamplingMode = 'sample';
%% Setup functional port to default
block.SetPreCompPortInfoToDefaults;
%% Setup output port
block.SampleTimes = [0 1];
block.SimStateCompliance = 'DefaultSimState';
block.RegBlockMethod('Start', #Start);
block.RegBlockMethod('Outputs', #Outputs); % Required
block.RegBlockMethod('Update', #Update);
block.RegBlockMethod('Terminate', #Terminate); % Required
block.RegBlockMethod('SetInputPortSamplingMode', #SetInpPortFrameData);
block.RegBlockMethod('PostPropagationSetup', #DoPostPropSetup);
function DoPostPropSetup(block)
% Setup Dwork
block.NumDworks = 4;
block.Dwork(1).Name = 'Nothing';
block.Dwork(1).Dimensions = 1;
block.Dwork(1).DatatypeID = 0;
block.Dwork(1).Complexity = 'Real';
block.Dwork(1).UsedAsDiscState = false;
block.Dwork(2).Name = 'Nothing1';
block.Dwork(2).Dimensions = 1;
block.Dwork(2).DatatypeID = 0;
block.Dwork(2).Complexity = 'Real';
block.Dwork(2).UsedAsDiscState = false;
block.Dwork(3).Name = 'Nothing2';
block.Dwork(3).Dimensions = 1;
block.Dwork(3).DatatypeID = 0;
block.Dwork(3).Complexity = 'Real';
block.Dwork(3).UsedAsDiscState = false;
block.Dwork(4).Name = 'Nothing3';
block.Dwork(4).Dimensions = 1;
block.Dwork(4).DatatypeID = 0;
block.Dwork(4).Complexity = 'Real';
block.Dwork(4).UsedAsDiscState = false;
%endfunction
%endfunction
function Start(block)
fullpathToDll = 'Z:\Farha\2015_02_26_photometer_Datenlogger\PC-Software\CGMultChan.dll';
fullpathToHeader = 'Z:\Farha\2015_02_26_photometer_Datenlogger\PC-Software\CGMultChan.h';
fullpathToHeader;
fullpathToDll;
loadlibrary(fullpathToDll, fullpathToHeader);
libfunctions ('CGMultChan');
delete(instrfindall);
serialPort = 'COM1';
IP = calllib('CGMultChan', 'CGMultChan_Connect', '192.168.100.158'); %Connect to Data Loger
if (IP == 0)
end
out = instrfind('Port', 'COM1');
%Open Serial COM Port
s = serial(serialPort);
set(s, 'BaudRate', 57600, 'DataBits', 8, 'Parity', 'none', 'StopBits', 1, 'FlowControl', 'none', 'Terminator', 'CR');
set(s, 'Timeout', 20);
fopen(s);
TI_ms = calllib('CGMultChan', 'CGMultChan_SetIntTime', .02 * 100);
tic
block.Dwork(1).Data = 1;
block.Dwork(2).Data = 2;
block.Dwork(3).Data = 3;
block.Dwork(4).Data = 5;
function Outputs(block)
block.OutputPort(1).Data = block.Dwork(1).Data; %+ %block.InputPort(1).Data;
block.OutputPort(2).Data = block.Dwork(2).Data;
block.OutputPort(3).Data = block.Dwork(3).Data;
block.OutputPort(4).Data = block.Dwork(4).Data;
count = 0;
function Update(block)
nsamples = 20
count = 0
while (count < nsamples)
BufferSize = 16;
pBuffer = libpointer('singlePtr', zeros(BufferSize, 1));
data2 = calllib('CGMultChan', 'CGMultChan_MeasureAll', pBuffer); %Measurement
output = pBuffer.Value
count = count + 1;
time(count) = toc; %Extract Elapsed Time
dataright(count) = output(1)
dataup(count) = output(2)
databack(count) = output(3)
datafront(count) = output(5)
end
dataright(1:20) = output(1:20);
dataup(1:20) = output(1:20);
databack(1:20) = output(1:20);
datafront(1:20) = output(1:20);
block.Dwork(1).Data = double(dataright(1));
block.Dwork(2).Data = double(dataup(2));
block.Dwork(3).Data = double(databack(3));
block.Dwork(4).Data = double(datafront(5));
%end Update
function SetInpPortFrameData(block, idx, fd)
block.InputPort(idx).SamplingMode = fd;
for i = 1:block.NumOutputPorts
block.OutputPort(i).SamplingMode = fd;
end
%%
function Terminate(block)
serialPort = 'COM1';
s = serial(serialPort);
fclose(s);
clear pBuffer;
calllib('CGMultChan', 'CGMultChan_Disconnect'); %Disconnect from Data Logger
This is a Level 2 S function code which generates simulink block. It connects a data logger with computer. That means its an object oriented code. I solved the problem changing the buffer size pbuffer=500. So that matrix size of data output is increased.

How can I display greek symbols in Matlab GUI

How can I use the degree symbol when writing a GUI in Matlab? I can use ^\circ when plotting but this does not work when writing a GUI.
This is my GUI so far:
directory = 'Data';
SiteName = 'AAA';
done = false;
spcFrac = 2; %number of spaces = char;
num2delim = 20;
defSlt = 'aTemp';
loader = 'on';
fclose all;
outputOptions = {'Air temperature','aTemp'};
defaults = {'',''};
% long names for outputs
names = {'latitude (deg N)','altitude (m)'};
lines = [4,5];
[~,b] = sortrows(outputOptions); vL = length(b);
outN = cell(vL,1);outA = outN;outUn = outN;
for k = 1:length(b)
outUn{k}= outputOptions{b(k),1};
outN{k} = outputOptions{b(k),1};
outA{k} = outputOptions{b(k),2};
end
indx = strcmp(defSlt,outA);
slt{1} = outN{indx};
txt = outA{indx};
outN(indx) = [];
close all
bckColor = [.85 .85 .85];
figDims = [150 150 400 300];
lM = 15;
tM = 20;
rM = 15;
bM = 15;
pnS = 12;
bgPw = 180;
bgPh = 120;
btnH = 25;
txtH = 20;
txtW = 40;
txtS = 5;
spc = 9;
radioW = 150;
radioH = 20;
bigPanels(1,:) = [lM figDims(4)-bgPh-tM bgPw bgPh];
bigPanels(2,:) = bigPanels(1,:); bigPanels(2,1) = bigPanels(2,1)+pnS+bgPw;
filePanel = [bigPanels(2,1)+bgPw+pnS*2 bM+pnS+btnH ...
figDims(3)-bgPw*2-lM-pnS*3-rM figDims(4)-tM-pnS-btnH-bM];
btns(1,:) = [lM bigPanels(1,2)-spc-btnH bgPw btnH];
btns(2,:) = [bigPanels(2,1) bigPanels(1,2)-spc-btnH bgPw btnH];
btns(3,:) = [filePanel(1)+filePanel(3)-bgPw bM bgPw btnH];
btns(4,:) = [filePanel(1) bM radioW radioH];
numTxtIn = numel(defaults);
rowsTxt = ceil(numTxtIn/2);
for p = 1:rowsTxt
txtBoxL(p,:) = [lM bM+(p-1)*(pnS+txtH) txtW txtH];
txtBoxR(p,:) = [lM+pnS+bgPw bM+(p-1)*(pnS+txtH) txtW txtH ];
diaL(p,:) = [lM+txtW+txtS -txtS+bM+(p-1)*(pnS+txtH) txtBoxR(p,1)-...
lM-txtW-pnS txtH ];
diaR(p,:) = [txtBoxR(p,1)+txtW+txtS -txtS+bM+(p-1)*(pnS+txtH) ...
txtBoxR(p,1)-lM-txtW-pnS txtH ];
end
S.fh = figure('units','pixels',...
'position',figDims,...
'menubar','none',...
'resize','off',...
'numbertitle','off',...
'name','Configuration File','Color',bckColor);
movegui(S.fh,'center')
outFrame=uipanel('Parent',S.fh,'BackgroundColor',bckColor,...
'Title','Output options','FontSize',10);
setpixelposition(outFrame,[lM-spc btns(1,2)-spc ...
bgPw+spc*2 bgPh+btnH+spc*3+pnS]);
slcFrame=uipanel('Parent',S.fh,'BackgroundColor',bckColor,...
'Title','Output selections','FontSize',10);
setpixelposition(slcFrame,[bigPanels(2,1)-spc btns(1,2)-spc ...
bgPw+spc*2 bgPh+btnH+spc*3+pnS]);
ParamFrame=uipanel('Parent',S.fh,'BackgroundColor',bckColor,...
'Title','User parameters','FontSize',10);
setpixelposition(ParamFrame,[btns(1,1)-spc ...
bM-spc bgPw*2+pnS+spc*2 btns(1,2)-2*spc-2]);
for lm = 1:rowsTxt
indr = rowsTxt-lm+1;
S.outT(1,indr) = uicontrol('style','edit',...
'units','pix',...
'position',txtBoxL(indr,:),...
'HorizontalAlign','center',...
'string','Remove',...
'fontsize',8,'String',defaults{lm,1},...
'callback',{#txt_call,lines(lm,1)},...
'BackgroundColor','w');
S.outT(2,indr) = uicontrol('style','edit',...
'units','pix',...
'position',txtBoxR(indr,:),...
'HorizontalAlign','center',...
'string','Remove',...
'fontsize',8,'String',defaults{lm,2},...
'callback',{#txt_call,lines(lm,2)}...
,'BackgroundColor','w');
S.outD(1,indr) = uicontrol('style','text',...
'units','pix',...
'position',diaL(indr,:),...
'HorizontalAlign','left',...
'string','Remove',...
'fontsize',8,'String',names{lm,1},'BackgroundColor',bckColor);
S.outD(2,indr) = uicontrol('style','text',...
'units','pix',...
'position',diaR(indr,:),...
'HorizontalAlign','left',...
'string','Remove',...
'fontsize',8,'String',names{lm,2},'BackgroundColor',bckColor);
end
Here I would like to change degN into the degree symbol ^\circ does not work.
Depending on the symbols you want to use, you can use either extended ascii or unicode symbols. So, for instance, ^\circ is Alt+0176 which gives you ° (numbers must be typed on keypad and the zero is necessary). µ is Alt+0181, etc. If that doesn't work, you can also programmatically use char(). So char(176) will give you the degree sign.
I should add that the Alt+0XXX construct is a MS Windows (it's worked as far back as 95 AFAIK) shortcut. I am certain-ish that there are similar keyboard shortcuts for MacOS and your favorite flavor of *nix. The char command works everywhere.
From your example code above, you just need to change the definition of names:
names = {'latitude (°N)','altitude (m)'};
or
names = {['latitude (' char(179) 'N)'],'altitude (m)'};

Converting Matlab gaussian derivatives to Opencv

I trying to convert an old exercise i made in matlab to OpenCV. Code is posted below. I havent been able to find any functions in OpenCv that does what i want, might be because of other names then what i expect.
Here are the outputs when taken the max response in each location as label. Clearly somethings wronge.
Here is the matlab code:
function responses = getBifResponsesEx(im, myEps, sigma, kernelSize)
if ( nargin == 3 )
if ( sigma >= 1 )
kernelSize = 6*sigma + 1;
else
kernelSize = 7;
end
end
responses = zeros(size(im,1), size(im,2), 7);
%
% Gaussian derivatives
%
kernVal = ceil(kernelSize/2) - 1;
x = (-kernVal:kernVal);
g = 1/(2*pi*sigma^2)*exp(-(x.^2./(2*(sigma^2))));
g = g/sum(g);
dg = -2*x/(2*sigma^2).*g*sigma;
ddg = ((2*x/(2*sigma^2)).^2 - 1/(sigma^2)).*g*sigma;
%
% Gaussian convolution of the image
%
s00 = filter2(g, im);
s00 = filter2(g', s00);
s10 = filter2(g', im);
s10 = filter2(dg, s10);
s01 = filter2(g, im);
s01 = filter2(dg', s01);
s11 = filter2(dg, im);
s11 = filter2(dg', s11);
s20 = filter2(g', im);
s20 = filter2(g', s20);
s20 = filter2(ddg, s20);
s02 = filter2(g, im);
s02 = filter2(g, s02);
s02 = filter2(ddg', s02);
%
% Symmetry types - MISSING CODE!!!!
%
lam = sigma^2*(s20+s02);
gam = sigma^2*(sqrt((s20-s02).^2+4*s11.^2));
responses(:,:,1) = myEps*s00;
responses(:,:,2) = 2*sigma*sqrt(s10.^2+s01.^2);
responses(:,:,3) = +lam;
responses(:,:,4) = -lam;
responses(:,:,5) = 2^-.5*(gam+lam);
responses(:,:,6) = 2^-.5*(gam-lam);
responses(:,:,7) = gam;
end
And here is my converted page. From what i can see, it goes wronge with the s20,s02 responses. Anyone able to tell me what to do?
void extract_bif_features(const cv::Mat & src,
std::vector<cv::Mat> & dst, BIFParams params)
{
float sigma = params.sigma;
float n=0;
int kernelSize;
if(sigma>=1)
kernelSize = 6*sigma + 1;
else
kernelSize = 7;
cv::Mat gray,p00,p10,p01,p11,p20,p02;
cv::cvtColor(src,gray,CV_BGR2GRAY);
auto kernVal = (int)ceil(kernelSize/2.0) - 1;
cv::Mat_<float> g(1,kernelSize);float*gp = g.ptr<float>();
cv::Mat_<float> dg(1,kernelSize);float*dgp = dg.ptr<float>();
cv::Mat_<float> ddg(1,kernelSize); float*ddgp = ddg.ptr<float>();
cv::Mat_<float> X(1,kernelSize);float*xp = X.ptr<float>();
auto gsum=0.0f;
for(int x = -kernVal;x<=kernVal;++x)
{
xp[x+kernVal] = x;
gp[x+kernVal] = 1/(2*CV_PI*sigma*sigma)*exp(-(x*x/(2*(sigma*sigma))));
gsum += gp[x+kernVal];
}
g = g/gsum;
cv::multiply((-2*X / (2*sigma*sigma)),g*sigma,dg);
cv::pow((2*X/(2*sigma*sigma)),2,ddg);
ddg -=1/(sigma*sigma);
cv::multiply(ddg,g*sigma,ddg);
std::cout << ddg<< std::endl;
std::cout << dg<< std::endl;
cv::sepFilter2D(gray,p00,CV_32FC1,g,g,cv::Point(-1,-1),0.0,cv::BORDER_REPLICATE); cv::sepFilter2D(gray,p01,CV_32FC1,dg,g,cv::Point(-1,-1),0.0,cv::BORDER_REPLICATE); cv::sepFilter2D(gray,p10,CV_32FC1,g,dg,cv::Point(-1,-1),0.0,cv::BORDER_REPLICATE); cv::sepFilter2D(gray,p11,CV_32FC1,dg,dg,cv::Point(-1,-1),0.0,cv::BORDER_REPLICATE);
//NOT SURE HERE
cv::sepFilter2D(gray,p20,CV_32FC1,g,ddg,cv::Point(-1,-1),0.0,cv::BORDER_REPLICATE);
//cv::sepFilter2D(p20,p20,CV_32FC1,1,g,cv::Point(-1,-1),0.0,cv::BORDER_REPLICATE); cv::sepFilter2D(gray,p02,CV_32FC1,g,ddg,cv::Point(-1,-1),0.0,cv::BORDER_REPLICATE); //cv::sepFilter2D(p02,p02,CV_32FC1,g,1,cv::Point(-1,-1),0.0,cv::BORDER_REPLICATE);
cv::filter2D(gray,p20,CV_32FC1,g,cv::Point(-1,-1),0.0,cv::BORDER_REPLICATE);
cv::filter2D(p20,p20,CV_32FC1,g,cv::Point(-1,-1),0.0,cv::BORDER_REPLICATE);
cv::filter2D(p20,p20,CV_32FC1,ddg,cv::Point(-1,-1),0.0,cv::BORDER_REPLICATE);
cv::filter2D(gray,p02,CV_32FC1,g,cv::Point(-1,-1),0.0,cv::BORDER_REPLICATE);
cv::filter2D(p02,p02,CV_32FC1,g.t(),cv::Point(-1,-1),0.0,cv::BORDER_REPLICATE);
cv::filter2D(p02,p02,CV_32FC1,ddg.t(),cv::Point(-1,-1),0.0,cv::BORDER_REPLICATE);
dst.resize(6);
auto sigma_square = sigma*sigma;
cv::Mat Lam = sigma_square * (p20+p02);
cv::Mat Gam ;
cv::sqrt((((p20-p02)*(p20-p02))+4*p11*p11),Gam);
Gam *= sigma_square ;
cv::Mat test = p10*p10;
//slop
cv::sqrt(p10*p10 + p01*p01,dst[0]);
dst[0] = dst[0]*2*sigma;//slop
//blob
dst[1] = Lam;
dst[2] = -1*Lam;
//line
dst[3] = sqrt(2.0f)*(Gam+Lam);
dst[4] = sqrt(2.0f)*(Gam-Lam);
//saddle
dst[5] = Gam;
}
The answer is from what i get sofar.
cv::multiply((p20-p02),(p20-p02),Gam); is not the same as Gam = (p20-p02)*(p20-p02);
Full Code: Classify according to higest response, Griffin(2008).
RIDAR_API void extract_bif_features(const cv::Mat & src,
std::vector<cv::Mat> & dst, BIFParams params)
{
float sigma = params.sigma;
float eta = params.eta;
int kernelSize;
if(sigma>=1)
kernelSize = 4*sigma + 1;
else
kernelSize = 5;
auto kernVal = (int)ceil(kernelSize/2.0) - 1;
cv::Mat_<float> g(1,kernelSize);float*gp = g.ptr<float>();
cv::Mat_<float> X(1,kernelSize);float*xp = X.ptr<float>();
auto gsum=0.0f;
for(int x = -kernVal;x<=kernVal;++x)
{
xp[x+kernVal] = x;
gp[x+kernVal] = 1/(2*CV_PI*sigma*sigma)*exp(-(x*x/(2*(sigma*sigma))));
gsum += gp[x+kernVal];
} g = g/gsum;
cv::Mat dg = -2*X.mul(g*sigma) / (2*sigma*sigma);
cv::Mat ddg = ((2*X/(2*sigma*sigma)).mul((2*X/(2*sigma*sigma))) - 1/(sigma*sigma)).mul(g*sigma);
cv::Mat gray,p00,p10,p01,p11,p20,p02;
cv::cvtColor(src,gray,CV_BGR2GRAY);
cv::filter2D(gray,p00,CV_32FC1,g);
cv::filter2D(p00,p00,CV_32FC1,g.t());
cv::filter2D(gray,p10,CV_32FC1,g.t());
cv::filter2D(p10,p10,CV_32FC1,dg);
cv::filter2D(gray,p01,CV_32FC1,g);
cv::filter2D(p01,p01,CV_32FC1,dg.t());
cv::filter2D(gray,p11,CV_32FC1,dg);
cv::filter2D(p11,p11,CV_32FC1,dg.t());
cv::filter2D(gray,p20,CV_32FC1,g.t());
cv::filter2D(p20,p20,CV_32FC1,g.t());
cv::filter2D(p20,p20,CV_32FC1,ddg);
cv::filter2D(gray,p02,CV_32FC1,g);
cv::filter2D(p02,p02,CV_32FC1,g);
cv::filter2D(p02,p02,CV_32FC1,ddg.t());
#ifdef DISPLAY_WHILE_RUNNING
double max,min;
cv::imshow("p00",p00/255);
//
cv::minMaxIdx(p01,&min,&max);
cv::imshow("p01",(p01-min)/(max-min));
//
cv::minMaxIdx(p10,&min,&max);
cv::imshow("p10",(p10-min)/(max-min));
cv::minMaxIdx(p11,&min,&max);
cv::imshow("p11",(p11-min)/(max-min));
cv::minMaxIdx(p02,&min,&max);
cv::imshow("p02",(p02-min)/(max-min));
cv::minMaxIdx(p20,&min,&max);
cv::imshow("p20",(p20-min)/(max-min));
cv::waitKey();
#endif
dst.resize(7);
auto sigma_square = sigma*sigma;
auto p2d = p20-p02;
//LAM
dst[2] = sigma_square * (p20+p02);
//GAM
cv::sqrt( (p2d).mul(p2d) + (4.0f * p11.mul(p11)) ,dst[6] );
dst[6] = dst[6] * sigma_square;
//FLAT
dst[0] = eta*p00;
//slop
cv::sqrt(p10.mul(p10)+p01.mul(p01),dst[1]);
dst[1] *= 2.0f*sigma;
//blob dst[2]
dst[3] = -dst[2];
//line
dst[4] = pow(2.0,-0.5)*(dst[6]+dst[2]);
dst[5] = pow(2.0,-0.5)*(dst[6]-dst[2]);
//saddle dst[6]
#ifdef DISPLAY_WHILE_RUNNING
double max,min;
cv::minMaxIdx(dst[0],&min,&max);//
cv::imshow("FLAT",(dst[0]-min)/(max-min));
cv::minMaxIdx(dst[1],&min,&max);//
cv::imshow("SLOPE",(dst[1]-min)/(max-min));
cv::minMaxIdx(dst[2],&min,&max);
cv::imshow("BLOB+",(dst[2]-min)/(max-min));
cv::minMaxIdx(dst[3],&min,&max);//
cv::imshow("BLOB-",(dst[3]-min)/(max-min));
cv::minMaxIdx(dst[4],&min,&max);//
cv::imshow("LINE+",(dst[4]-min)/(max-min));
cv::minMaxIdx(dst[5],&min,&max);
cv::imshow("LINE-",(dst[5]-min)/(max-min));
cv::minMaxIdx(dst[6],&min,&max);
cv::imshow("SADDLE",(dst[6]-min)/(max-min));
cv::waitKey();
#endif
}
why dont you take average on dg and ddg?
cv::filter2D(gray,p20,CV_32FC1,g.t());
cv::filter2D(p20,p20,CV_32FC1,g.t());
why take two times of filter here?
//GAM
cv::sqrt( (p2d).mul(p2d) + (4.0f * p11.mul(p11)) ,dst[6] );
dst[6] = dst[6] * sigma_square;
where you get this formula ?

How to make double[,] x_List in C#3.0?

I ned to implement the multi-linear regression in C#(3.0) by using the LinESt function of Excel.
Basically I am trying to achieve
=LINEST(ACL_returns!I2:I10,ACL_returns!J2:K10,FALSE,TRUE)
So I have the data as below
double[] x1 = new double[] { 0.0330, -0.6463, 0.1226, -0.3304, 0.4764, -0.4159, 0.4209, -0.4070, -0.2090 };
double[] x2 = new double[] { -0.2718, -0.2240, -0.1275, -0.0810, 0.0349, -0.5067, 0.0094, -0.4404, -0.1212 };
double[] y = new double[] { 0.4807, -3.7070, -4.5582, -11.2126, -0.7733, 3.7269, 2.7672, 8.3333, 4.7023 };
I have to write a function whose signature will be
Compute(double[,] x_List, double[] y_List)
{
LinEst(x_List,y_List, true, true); < - This is the excel function that I will call.
}
My question is how by using double[] x1 and double[] x2 I will make double[,] x_List ?
I am using C#3.0 and framework 3.5.
Thanks in advance
double[,] xValues = new double[x1.Length, x2.Length];
for (int i = 0; i < x1.Length; i++)
{
xValues[i, 0] = x1[i];
xValues[i, 1] = x2[i];
}
Actually it should be
double[,] xValues = new double[x1.Length, x2.Length];
int max = (new int[]{ x1.Length,x2.Length}).Max();
for (int i = 0; i < max; i++)
{
xValues[0, i] = x1.Length > i ? x1[i] : 0;
xValues[1, i] = x2.Length > i ? x2[i] : 0;
}
Samir is right, that i should call Max() once outside the iterator rather than each iteration, i've amended this.
The side of the multi-dimensional array is incorrect in both your answer and bablo's. In addition, the call to Max on every iteration in bablo's answer seems really slow, especially with large numbers of elements.
int max = (new int[] { x1.Length, x2.Length }).Max();
double[,] xValues = new double[2, max];
for (int i = 0; i < max; i++)
{
xValues[0, i] = x1.Length > i ? x1[i] : 0;
xValues[1, i] = x2.Length > i ? x2[i] : 0;
}