Adaptive Thresholding for liver segmentation using Matlab
I saw the link of the paper (of SS Kumar) you referred and the link where you got the code (HIPR) are two different algorithms - even though both sounds like Adaptive Thresholding 

First i would like to tell you the difference. 

In the HIPR method, a general assumption is essentially 2 class level image - i.e. foreground and background. In any 2 class thresholding, one expects 2 peaks or regions within the image histogram, specifically background vs. forground, text vs. white paper. If you somehow found an optimal valley point in the histogram - you get cleanest division. Here is how the histogram may look like :
 

However, this valley point may be slightly shifting around the locally. There are good examples of lighting variations given there. Hence, this optimal valley point exists everywhere but slightly varies spatially, hence a universal threshold would fail. Hence, the valley point (threshold) is computed on every local region. 

SS Kumar's paper's method and more specifically the class of images you are dealing with, is multi-class (multiple objects each with different intensity band and spread). In this cases, histograms are multi-modal, i.e. it has many peaks and valleys and presumably each peak correspond to different object, yet it may be even more complex. 

The histogram might just look like this: (this is the same image as in paper). 


In this case, the above 2 class approach will simply fail because there is no one good valley. Which is why your first image you posted looks like black/white dots all around. 

The meaning of Adaptive Thresholding here, implies that you need to identify the correct peak and the band of gray scale which covers most intensities of the lever and other objects are in stark contrasts which allows 

What should you do?  

First of, if it is compulsory to use Adaptive thresholding, find the histogram and see what intensity range and then for a threshold of left or to the right are the intensity boundaries which pixels should be discarded. 

Alternatively you can use Region Growing or split and merge algorithm. Refer to this question for some information: What segmentation methods can be used for simple images?