You are on page 1of 6

5 Equivalent MIPS and MATLAB functions

Aritmetics
MIPS out = add(in1,in2);
MATLAB out = in1 + in2;

MIPS out = imabs(in);


MATLAB out = abs(in);

MIPS out = imimag(in);


MATLAB out = imag(in)*sqrt(-1);

MIPS out = imphase(in);


MATLAB out = angle(in);

MIPS out = imreal(in);


MATLAB out = real(in);

MIPS out = mult(in1,in2);


MATLAB out = in1 .* in2;

MIPS out = s2u(in);


MATLAB out = in + 128;

MIPS out = scale(in,k);


MATLAB out = in * k;

MIPS out = sub(in1,in2);


MATLAB out = in1 - in2;

MIPS out = u2s(in);


MATLAB out = in - 128;

Binary opertions
Too complicated to describe shortly: distcad, distmap, distroute, distskel,
levialdi, logop, logop4, ocrdecide, thin1, thin2

MIPS out = contract(in, 8, iter);


MATLAB out = bwmorph(in, erode, iter);
MIPS out = contract(in, 4, 1);
MATLAB se = [1 1 1; 1 1 1; 1 1 1];
out = imerode(in, se);
MIPS out = expand(in, 8, iter);
MATLAB out = bwmorph(in, dilate, iter);
MIPS out = expand(in, 4, 1);
MATLAB se = [0 1 0; 1 1 1; 0 1 0];
out = imdilate(in, se);

MIPS [out,num] = labeling(in, conn);


MATLAB [L,num]=bwlabel(in,conn);
out = L;

MIPS out = ocrextract(in, object);


MATLAB if object == 0
num_objects = max(max(in));
[obj_hist,dummy] = imhist(mat2gray(in),num_objects+1);
[maxval,label] = max(obj_hist(2:end));
else
label = object;
end;
out = (in == label);

MIPS out = selectobj(in, mi, ma);


MATLAB num_of_objects = max(max(in));
in2 = mat2gray(in,[0 num_of_objects]);
[obj_hist,dummy] = imhist(in2, num_of_objects+1);
out = 0*in2;
for label=2:num_of_objects+1
if ( (obj_hist(label)>=mi) & (obj_hist(label)<=ma) )
out = out + (in == label-1);
end
end

Correlation
Too complicated to describe shortly: bpof, corr, corrc, corrdc, corrdcp,
corrn, pof, smoothpad, spof

Fingerprints
Too complicated to describe shortly: calcex, calcf2x, calclx, fingerimpl,
fingimp

MIPS out=calcAngle(iE1,iE2,0);
MATLAB angle = atan2(iE2,iE1);
out = ((angle<0).*(atan2(iE2,iE1)+2*pi) +
(angle>=0).*(atan2(iE2,iE1)))*255/(2*pi);

MIPS out=calcMagn(iE1,iE2);
MATLAB out = sqrt(iE1.^2+iE2.^2);
MIPS out=fingaver(in,averVariance,0);
MATLAB averKernel = exp(-((-averVariance:1:averVariance).^2)/
(averVariance*2));
averKernel = averKernel*averKernel/
(sum(sum(averKernel))^2);
out = conv2(in,averKernel,same);

MIPS out=fingeraver(in,no);
MATLAB simpleAver = [1 2 1 ;2 4 2 ;1 2 1]/16;
for k=1:no
in = conv2(in,simpleAver,same);
end
out = in;

Image enhancement
Too complicated to describe shortly: shadcorr, wiener

MIPS out = addnoise(g, SNR);


MATLAB n = randn(size(g));
sigma2n = std2(n)^2;
sigma2g = std2(g)^2;
n = sqrt((sigma2g/sigma2n)*10^(-SNR/10))*n;
out = g + n;

MIPS out = eqhist(in);


MATLAB out = round(255*histeq(mat2gray(in,[0 255]), 256));

Image sequences
Too complicated to describe shortly: optflow.m, rtf.m

Linear filters
Too complicated to describe shortly: circconv.m
Similar technique as for bpcfilter and lpcfilter:
bprfilter, bscfilter, bsrfilter, hpcfilter, hprfilter, lpcfilter,
lprfilter

MIPS out = average(in, region, gain);


MATLAB h = region*region*fspecial(average,[region region]);
out = conv2(in, h/gain, same);

MIPS out = bpcfilter(in, ifreq, ofreq);


MATLAB s = size(in);
[x y] = meshgrid(-s(2)/2:s(2)/2-1, -s(1)/2:s(1)/2-1);
ri2 = (ifreq * s(1)/2)^2;
ro2 = (ofreq * s(1)/2)^2;
d2 = x.^2 + y.^2;
m = (d2 > ri2) & (d2 < ro2);
out = in .* m;
MIPS out = convolve(in, kern, gain);
MATLAB out = conv2(in, kern/gain, same);

MIPS out = lpcfilter(in, freq);


MATLAB s = size(in);
[x y] = meshgrid(-s(2)/2:s(2)/2-1, -s(1)/2:s(1)/2-1);
r2 = (freq * s(1)/2)^2;
d2 = x.^2 + y.^2;
m = d2 < r2;
out = in .* m;

MIPS out = magngrad(in, sobel);


MATLAB sobel = [1 2 1;0 0 0;-1 -2 -1];
lx = conv2(in, sobel', 'same');
ly = conv2(in, sobel, 'same');
out = sqrt(lx.^2 + ly.^2) / 4/ sqrt(2);

Logical functions
MIPS out = andBinary(in1, in2);
MATLAB out = double(in1 & in2);

MIPS out = invert(in);


MATLAB out = 1 - in;

MIPS out = orBinary(in1, in2);


MATLAB out = double(in1 | in2);

Nonlinear filters
Too complicated to describe shortly: nagao

MIPS out = median2(in, region);


MATLAB out = medfilt2(in,[region region]);

Resampling
Too complicated to describe shortly: rect2pol, resample

MIPS out = rotate(in, angle, type);


MATLAB out = imrotate(in, angle, bilinear, crop);

Statistics
MIPS out = distanshistogram(in);
MATLAB [counts, positions] = imhist(mat2gray(in,[0 255]));
counts(1) = 0;
out = counts;

MIPS out = histogram(in);


MATLAB [counts, positions] = imhist(mat2gray(in,[0 255]));
out = counts;
MIPS out = labelhistogram(in);
MATLAB [counts, positions] = imhist(mat2gray(in,[0 255]));
counts(1) = 0;
out = counts;

MIPS out = meanhist(in);


MATLAB siz = max(size(in));
x = (0:siz-1);
if size(in, 1) == 1
out = sum(in .* x) / sum(in);
else
out = x * in / sum(in);
end;

Thresholding
Too complicated to describe shortly: mittp, ocrselectthresh1,
ocrselectthresh2

MIPS out = threshold(in, level, type);


MATLAB if strcmp(<, type)
out = double(in<level);
if strcmp(>, type)
out = double(in>level);

Transforms
Too complicated to describe shortly: ihough

MIPS out = dft(in);


MATLAB [rows, cols] = size(in);
out = fftshift(fft2(fftshift(in)) / (rows * cols));

MIPS out = dft(in);


MATLAB [rows, cols] = size(in);
out = real(fftshift(ifft2(fftshift(in*(rows *cols)))));

MIPS out = hough(in);


MATLAB sx = size(in,1);
dtheta = 180/sx;
theta = 0:dtheta:180-dtheta;
R = radon(mat2gray(in,[0 255]),theta,sx);
out = flipud(round(R/max(max(R))*255));

Windows
MIPS out = gauss(in, gain, ssize);
MATLAB s = size(in);
[x y] = meshgrid(-s(2)/2:s(2)/2-1, -s(1)/2:s(1)/2-1);
r0 = ssize*s(1);
a = r0^2/log(.1);
out = exp( (x.^2+y.^2)/a ) * gain .* in;
MIPS out = hamming(in, gain, ssize);
MATLAB s = size(in);
[x y] = meshgrid(-s(2)/2:s(2)/2-1, -s(1)/2:s(1)/2-1);
R = sqrt(sum(s.^2)/8);
tmp = (0.54 + 0.46*cos(pi*sqrt(x.^2+y.^2)/(R*ssize))) *
gain .* in;
out = lpcfilter(tmp, ssize);

MIPS out = hanning(in, gain, ssize);


MATLAB s = size(in);
[x y] = meshgrid(-s(2)/2:s(2)/2-1, -s(1)/2:s(1)/2-1);
R = sqrt(sum(s.^2)/8);
tmp = (0.5 + 0.5*cos(pi*sqrt(x.^2+y.^2)/(R*ssize))) *
gain .* in;
out = lpcfilter(tmp, ssize);

Some MIPS functions not reachable from the Operation window


MIPS colimage(in,gray,1,1);
MATLAB figure;
colormap(gray);
imagesc(in);
axis image;
MIPS colimage(in,gray,0,0);
MATLAB figure(99);
colormap(gray);
imagesc(in,[0,255]);
axis image;
Note also that MATLAB have other colortables not reachable from MIPS and vice versa.

MIPS out = chooseobject(in,x,y,xsize,ysize);


MATLAB out = in(y+1:y+ysize,x+1:x+xsize);
MIPS out = chooseobject(in,x,y,size);
MATLAB out = in(y+1:y+size,x+1:x+size);
Note also that Cut in the Display window can be used for this task.

You might also like