08-02-2017, 02:31 PM
Code:
function code=Dec2Binfar(Tcod8,DIFLcd)
LT=length(Tcod8);
Lcd=LT*8-DIFLcd;
k=8;
for j=1:LT
for i=0:7
cd(k-i)=fix(Tcod8(j)/(2^(7-i)));
if Tcod8(j)>=2^(7-i)
Tcod8(j)=Tcod8(j)-2^(7-i);
end;
end;
k=k+8;
end;
for i=1:Lcd
code(i)=cd(i);
end;
Code:
function [DIFLcd,Tcod8]=Binfar2Dec(code)
L=length(code);
Lcd=round(L/8);
if mod(L,8)<4
if mod(L,8)~=0
Lcd=Lcd+1;
end
end
Lcdn=(Lcd)*8 ;
DIFLcd=(Lcdn)-L ;
codn=zeros(1,Lcdn);
k=1;
for i=1:L
codn(k)=code(i);
k=k+1;
end
Tcod8=zeros(1,Lcd);
k=1;
for i=1:Lcd
for j=0:7
Tcod8(i)=(codn(k+j))*(2^j)+Tcod8(i);
end;
k=k+8;
end;
% Function of Binfar2Dec (Binary To Decimal) was used on program of gray level image compression .
% Author : Said BOUREZG
% Electronics Engineer option:communication .
% Date : 11.28.2010
% Filename Binfar2Dec.m (Matlab)
can you test these matlab codes for mri brain tumor segmentation ?
read me
Code:
%If you have your vector of pulses for example:
%code=[1 0 0 0 1 0 1 1 0 1 0 1 0 0 0 1 0 1 1 1 1];%This is the which we want to cmpress it.
%Now we can call to our function :
%[DIFLcd,Tcod8]=Binfar2Dec(code)
%DIFLcd =
% 5
%Tcod8=
% 139 81 120
%Here code is the Input, DIFLcd and Tcod8 are the Output, in DIFLcd=5 is
%the value of zeros added to the end of the code vector to be able to
%translate it to decimal values: DIFLcd=length(Tcod8)*8-length(code)
%We can use this function only with values of vetors 0 or 1.
%Binfar2Dec.m : Binary To Decimal function
%Dec2Binfar.m : Decimal To Binary function
%K=[85 3 41];
%code=Dec2Binfar(K,3)
%code=
% 0 1 0 1 0 1 0 1 0 0 0 0 0 0 1 1 0 0 1 0 1