Configuring Samba as a Home File-Server

Samba is a very powerful software that can act as File-server & print-server using SMB/CIFS protocol. Here I describe a Home environment  and provide a appropriate Samba server configuration.
Samba is installed correctly and it execute with out issues.
Samba configuration file is located in /etc/samba
Samba Configuration file name is smb.conf ( This is the default )
Samba is installed on Debian Linux distribution. ( This should not matter much )

Description of the Home Environment
  • A Linux server with huge disk-space
  • A Mac desktop system
  • A Windows XP desktop
  • Office Laptop that needs to work in both Office and Home environment
  • A DSL Internet from ISP. DSL model Cum wireless router acts as the firewall for Home Network
  • All these computers form a private network behind the firewall and Wifi security is enabled for wireless connections.
Samba File Server Requirements
  • A common folder accessible to all home computers and office laptop while operating under home profile.
  • A private folder for each of the family members
  • The common folder should be available only for the trusted systems. That is,
    the systems I identify as trusted. For example, if one of my friend
    visits my house and plugs his computer in my network, the common folder
    should not be accessible from his computer.
  • Private folder of User A should not be accessible by User B
  • Samba service is only available with in the private network and must not be accessible from the Internet.
Links to Refer
smb.conf File That Satisfies The Above Requirements
netbios name = squad
server string = Siva’s File Server
invalid users = backup,bin,daemon,games,gnats,irc,list,lp,mail,man,news,proxy,root,sshd,sync,
workgroup = HOME
os level = 34
valid users = @users

browseable = yes
comment = Common folder for family members
path = /path/to/directory
writeable = yes
force group = users
create mode = 770
directory mode = 770
browseable = no
read only = no

A Simple De-speckle Algorithm

This algorithm attempts to find out whether a Pixel is a speckle in the scanned Image. A speckle can be roughly defined as an Impulse noise that has a very high/low value compared to its neighbors.
Normally, a median filter is good in reducing the speckle. But, applying median to remove speckle is not efficient. So an efficient way to do de-speckle is determine whether a pixel is a speckle and then apply Median or some other averaging technique.
Here is a way you can determine whether a pixel is a speckle quite fast. For this method to work you need to analyze the speckle pattern offline to figure out the threshold value.
Void SpeckleDetectAndCorrect ( char * source, int NumPixels )
/* We assume that the pixel of inerest is NumPixels/2+1. That is if the NumPixels is 5, then the 3rd pixel is the point of interest.*/
sum = source[0] + source[1] + source[3] + source[4];
Average = sum /4 ;
if (( Average – source[2]) > abs(20) )
/*this is a speckle Hence Apply Median*/
ApplyMedian(source, NumPixels )

Converting Optical Density of a Neutral Target into its RGB code value

Converting Optical Density of a Neutral Target into its RGB code value
Recently a Color Science  expert who I worked with reviewed this post and here is his comment:
Everything you have is correct.  However, in talking about scanners I think you should make it very clear that you are speaking about the linear response of the scanner.  The work you did on scanners was very much at the core of the true engineering that goes into making a good scanner and dealt with the data before subsequent image processing and color management.
Most people, however are used to seeing the scan data after it goes through gamma correction and image processing (trivial image processing stuff).  Gamma correction is applied “approximately” as such:
CV = 255*T^(1/2.4)
So, your 0.5 transmittance sample will have an 8 bit code value of 191 .  This is further complicated by the fact that my equation above is a simplification of the true 2.2 gamma function (the fact that I use 2.4 instead of 2.2 approximates the effect of an offset term) .  Also, not everyone uses sRGB and there are some 1.8 gamma scanners out there.  Finally, the scanner manufacturer may apply some color management which would further confuse the issue.
Long story short:  Just make it clear that your discussion is on the Linear Response.
====== Original Post Below=======
Well, the headline seems nerdy. Not really if you are into scanner world. This post it very much a knowledge sharing as I could not find anywhere in the net which says how to do the conversion. Not that it is difficult, but takes some understanding and head twitching to do the conversion.
To know what is Optical Density, refer to this wikipedia article . In layman terms, OD is a unit less measurement of  how much light passes through a sample.
Formula to know
OD_lambda = log_{10} O = - log_{10} T = - log_{10} left ({I over I_0} right )
O= the per-unit opacity
T= the per-unit transmittance
I0= the intensity of the incident light beam
I= the intensity of the transmitted light beam
if you want a sample to have 50% transmittance, then OD of that sample is
OD (50%) =  -log(.50) = 0.3
A neutral target is one that has equal amount of RGB color coded in it. A OD 0.3 neutral target is one whose transmittance is 50%. Now you ask what is the RGB value of the OD 0.3 neutral target. If we consider 8 bit RGB value, then 0 stands for black and 255 stands for white. For 50% transmittance, then the value should be exactly half and it is 128 for R,G & B.
Now let us say you want to prepare a sample that has OD of 0.6. RGB value for OD 0.6 can be obtained as below
-log10(x) = 0.6
x = 10−0.6  ( Should be read as 10 to the power of -0.6 )
X = .25  ( This is 25% transmittance. )
Hence the RGB code will be ( .25 X 256 ) =  64 each ( i.e R=64, G=64,B=64)
Another example, OD of .08
-log10(x) = .08
x = 10−0.08  ( Should be read as 10 to the power of -0.08)
X = .83  ( This is 83% transmittance. )
Hence the RGB code will be ( .83X 256 ) =  212 each ( i.e R=212, G=212,B=212)

Effecient Sorting Algorithm For Applying Median Filter to a Image

Normally median filters are applied to remove speckle noises in an Image. There are many variations of Median Filters but all these variations are for choosing the kernel dimensions and shape. What i mean by kernel is that it could be a 3X3 kernel or 5X4 kernel or a radius 3 kernel.
A 3×3 kernal will have 9 elements to sort
A 5X5 kernal will have 25 elements to sort
A radius 3 kernel will have 29 elements to be sorted before you can pick the median.
Bottom line is you choose any variations of kernals, it boils down to efficiency of sorting. I have come up a one such algorithm that i think is very efficient for Median Filtering
  1. RGB Planar data. The bit depth Per pixel is 8 bits.
  2. Median Filter Kernel size is Odd Number. Like 5, 9, 25 etc
  3. The following code is PseuodCode and good for one dimensional data.
A pseudo Code implementation of the Algorithm is shown below:
Global First_Element
Global Median_Value
Global PointOfInterest
Global Array [ 256 ] /* This assumes a bitDepth of 8. That is a Red Pixel is 8 bits in length.
Int FirstTimeSort ( char * sourceAddr, int NumberOfElementsToBeSorted )
int i , j;
// Reset all elements to 0
ZERO( Array)
for ( i = 0; i < NumberOfElementsToBeSorted; i++ )
/* The value in the sourceAddr must be between 0 and 255 */
/* We use values in SourceAddr to index into the Bucket. Then we increment to keep track of the repitations of the same number. If any value in sourceAddr is unique, then the Bucket count for that unique will be 1. */
Bucket[ sourceAddr[i] ] = Bucket[ sourceAddr[i] ] + 1 ;
/* At this point the values are sorted */
/* Now find the median*/
median = NumberOfElementsToBeSorted/2 +1
for ( i = 0, j=0; i < 256, j >= median, i++ )
j += Bucket[i];
Median_Value = i;
First_Element = sourceAddr[0];
PointOfInterest = sourceAddr[median -1 ]; /* C arrays are 0 indexed. Hence if you want to access the third element, you have to index array[2] */
return Median_Value;
Int SubsequentSort ( char * sourceAddr, int NumberOfElementsToBeSorted )
int i , j;
Bucket[First_Element] -= 1;
Bucket[Median_Value] += 1;
Bucket[PointOfInterest ] -= 1;
Bucket[sourceAddr[NumberOfElementsToBeSorted-1]] += 1;
/* At this we have sorted all our values */
/* Now find the median*/
median = NumberOfElementsToBeSorted/2 +1
for ( i = 0, j=0; i < 256, j >= median, i++ )
j += Bucket[i];
Median_Value = i;
First_Element = sourceAddr[0];
PointOfInterest = sourceAddr[median -1 ];
return Median_Value;
The following code snippet shows how to use the above routines.
int main ()
char * source = 0;
char * PointOfInterest = 0;
int KernelSize;
source = SourceOfBuffer /* Point to the source of Buffer that holds the image to which we need to apply median filter */
PointOfInttest = source+2; /* Applying 1 dimensional Median filter. There is no difference for 2 dimensional kernel as well. */
KernelSize = 5; /* So the median will always be he third element of the sorted array */
/* Do a first tme sort */
*PointOfIntrest = FirstTimeSort ( source, KernelSize );
/* Now do subsequent sorts */
PointOfIntrest += 1;
source += 1;
Until ( END OF ( source ) )
*PointOfIntrest = SubsequentSort(source, KernelSize );
PointOfIntrest += 1;
source += 1;

How to Avoid Integer overflow in C?

Here is the General Way to avoid integer overflow
Example 1
value = value + 100;
if ULONG_MAX – 100 >= value
then No Overflow
Example 2
x = x * 10 + r;
To Check whether x would overflow, do the following before you execute the above sentence
if ULONG_MAX – r/10 >= x
No Overflow
NOTE:ULONG_MAX is normally defined in limits.h. And it is dependent on the Processor.

How to add Swap partition in Debian/Ubuntu

RAM is composed of chunks of memory called Pages.  When programs execute, it takes fills up pages. Due to this sooner or later memory will run out. In order to free up the RAM, Pages can be swapped into hard drive and the freed up RAM can be used by the other program which needs CPU’s attention.
Swap space is not a must in Linux. So if you happen to have a system that does not have Swap space, then follow the below guide to create a swap file and use it.
Check whether a SWAP space is enabled
sudo swapon -s
if you do not have swap enabled in the system you should see the output as below
Filename                                Type            Size    Used    Priority
Check the system for available space.
The recommended swap file size is twice the size of the RAM size. If your RAM
size is 512 MB, then the SWAP file size should be 1GB.
Filesystem           1K-blocks      Used        Available Use% Mounted on
/dev/vda              20642428   2367536    17226316  13% /
tmpfs                   254432         0                  254432   0% /lib/init/rw
udev                    249612        60                   249552   1% /dev
tmpfs                   254432         4                    254428   1% /dev/shm
Allocate space for swapfile
sudo fallocate -l 1GB  /swapfile
Create Swap file 
sudo mkswap /swapfile
the output will look like below
Setting up swapspace version 1, size = 8388608 KiB
no label, UUID=103c4545-5fc5-47f3-a8b3-dfbdb64fd7eb
Turn on the SWAP file
sudo swapon  /swapfile
You will then be able to see the new swap file when you view the swap summary.
swapon -s
Filename    Type  Size Used Priority
/swapfile                               file  8388608 0 -1
TO add this partition permanently, add it into /etc/fstab
sudo nano /etc/fstab
/swapfile  none  swap  sw  0  0
save and close the fstab file.

C++ Operator Functions Declaration

A summary on how the different operator functions, in C++,  have to be declared
(replace @ by the operator in each case):

                    PS: This is for my reference that I copied from

How to Mount SMB/CIFS network share in Linux

If you have a Home NAS and if it supports SMB/CIFS shares, then follow the steps below to mount those shares in a Linux System.

Prerequisite   Linux system must have “smbfs” and cifs-utils package installed.

Mount CIFS with the default local filesystem permissions:
# mkdir /mnt/mntpoint 
# mount -t cifs //server-name/share-name /mnt/mntpoint -o username=shareuser,password=sharepassword
For Example
 # mount -t cifs // /mnt/mntpoint -o username=shareuser,password=sharepassword
  • username=shareuser : specifies the CIFS user name.
  • password=sharepassword : specifies the CIFS password. If this option is not given then the environment variable PASSWD is used. If the password is not specified directly or indirectly via an argument to mount, mount will prompt for a password, unless the guest option is specified.
For further details and options, please read linux man page for mount.cifs(8). Also, please note that only root user can mount the filesystems.
If you want a particular filesystem to mounted at boot time, then enter a static information about the filesystem you want to mount in /etc/fstab.
For example, in /etc/fstab you need to enter 6 fields
“file system to be mounted”   “mount point”  “file type”  “options”  ” dump option” “file system check (fsck) value”
//  /mnt/mntpoint cifs  username=shareuser,password=sharepassword 0 0
if you want any user to mount this file system then do the following
//  /mnt/mntpoint cifs  username=shareuser,password=sharepassword,user 0 0
if you want to provide a resolvable hostname instead of IP address, then ensure that you have cifs-utils is installed. Otherwise you will fail to mount with error code -22 . If you do a dmesg after failure you will see the below message
cifs_mount failed w/return code = -22