Browse Source

Added three buttons for adjusting threshold methods: IsoData, Yen, Otsu

Aleksandr Lizin 9 years ago
parent
commit
2f1772d1e5

+ 52 - 2
imageprocessing/sliceMapCreator.py

@@ -34,6 +34,9 @@ class Sprite(object):
     numberOfSprites = 0
     slicesPerSprite = 0
 
+    thresholdIndex_otsu = 255
+    thresholdIndex_yen  =  255
+    thresholdIndex_isodata  =  255
 
 def __initializeSprite(imageFrom, imageTo, sliceShape, dtype):
 
@@ -192,8 +195,6 @@ def processFrames(frames, frameFrom, frameTo, imageFrom, imageTo, imgFormat, des
 
     del frames
 
-    # pdb.set_trace()
-
     return __resizeSprites(sprites, destSize, imgFormat)
 
 
@@ -235,8 +236,53 @@ def processFrame(frame, frameNumber, imageFrom, imageTo, zDownScalingFactor):
                 sprite.currentRow = 0
                 sprite.numberOfImagesInSprite = 0
 
+    sprite = calculateThresholdIndexes(sprite)
+
     return sprite
 
+def calculateThresholdIndexes(sprite):
+    from skimage.filters import threshold_otsu, threshold_yen, threshold_isodata
+
+    # pdb.set_trace()
+    
+    image = sprite.imagesAsArrays[0]
+
+    sliceMapWidth = len(image[0])
+    sliceMapHeight = len(image)
+
+    numberSlicesInSliceMap = sprite.numberOfImages if sprite.numberOfImages >= 1 else 1
+
+    RowInSliceMap = sprite.imagesPerRow
+    ColInSliceMap = sprite.imagesPerRow
+
+    sliceWidth = sliceMapWidth / ColInSliceMap;
+    sliceHeight = sliceMapHeight / RowInSliceMap;
+
+    numberOfCentralSlice = (numberSlicesInSliceMap - 1) / 2
+
+    x = numberOfCentralSlice / RowInSliceMap
+    xp = x * sliceWidth
+
+    y = numberOfCentralSlice - (x * RowInSliceMap)
+    yp = y * sliceHeight
+
+    centralSliceX0 = xp
+    centralSliceX1 = xp + sliceWidth
+
+    centralSliceY0 = yp
+    centralSliceY1 = yp + sliceHeight
+
+    centerSliceImage = image[centralSliceX0 : centralSliceX1, centralSliceY0 : centralSliceY1]
+
+    sprite.thresholdIndex_otsu = threshold_otsu(centerSliceImage)
+    sprite.thresholdIndex_yen  =  threshold_yen(centerSliceImage)
+    sprite.thresholdIndex_isodata  =  threshold_isodata(centerSliceImage)
+
+    print("thresholdIndex_otsu = " + str(sprite.thresholdIndex_otsu))
+    print("thresholdIndex_yen = " + str(sprite.thresholdIndex_yen))
+    print("thresholdIndex_isodata = " + str(sprite.thresholdIndex_isodata))
+
+    return sprite
 
 def generateInfo(sprites, frameFrom, frameTo, imageFrom, imageTo):
     logger.debug('sliceMapCreator generating and saving .js info file')
@@ -256,6 +302,10 @@ def generateInfo(sprites, frameFrom, frameTo, imageFrom, imageTo):
         infoObject['frameFrom'] = frameFrom
         infoObject['frameTo'] = frameTo
 
+    infoObject['thresholdIndex_otsu'] = firstSprite.thresholdIndex_otsu
+    infoObject['thresholdIndex_yen'] = firstSprite.thresholdIndex_yen
+    infoObject['thresholdIndex_isodata'] = firstSprite.thresholdIndex_isodata
+
     return infoObject
 
 

+ 18 - 2
static/js/generic-slider.js

@@ -42,7 +42,7 @@ GenericSlider = {
 
     },
 
-    initSlider: function(sliderElement, inputElements, minVal, maxVal, callbackOnChange, callbackOnReposition) {
+    initSlider: function(sliderElement, inputElements, minVal, maxVal, leftVal, rightVal, callbackOnChange, callbackOnReposition) {
         var slider = sliderElement,
             sliderInputs = inputElements;
 
@@ -54,7 +54,7 @@ GenericSlider = {
                 range: true,
                 min: minVal,
                 max: maxVal,
-                values: [ minVal, maxVal ],
+                values: [ leftVal, rightVal ],
                 slide: function( event, ui ) {
                     var values = ui.values;
 
@@ -93,5 +93,21 @@ GenericSlider = {
             slider.slider('values', values);
             callbackOnChange(values);
         });
+    },
+
+    setPosSlider: function(sliderElement, inputElements, leftVal, rightVal) {
+        var slider = sliderElement,
+            sliderInputs = inputElements;
+
+        $(sliderInputs[0]).val(leftVal);
+        $(sliderInputs[1]).val(rightVal);
+
+        slider.slider(
+            {
+                range: true,
+                values: [ leftVal, rightVal ],
+            }
+        );
+
     }
 }

+ 47 - 0
static/js/threeJsHelper/dist/threeJsHelper.js

@@ -294,6 +294,45 @@ IPE.app = {
                 }
             });
         });
+
+        $('input#adjust-isodata-thresholding-bottom-controls-container').on('click', function() {
+            console.log(textureInfo.info.thresholdIndex_isodata);
+            GenericSlider.setPosSlider(
+                slider = $( "#gray-slider" ),
+                sliderInputs = $('input.gray'),
+                minGray,
+                textureInfo.info.thresholdIndex_isodata
+            );
+            $(document).trigger('opacityBordersChanged', { minGray: minGray, maxGray: textureInfo.info.thresholdIndex_isodata});
+
+        });
+
+        $('input#adjust-otsu-thresholding-bottom-controls-container').on('click', function() {
+            console.log(textureInfo.info.thresholdIndex_otsu);
+            GenericSlider.setPosSlider(
+                slider = $( "#gray-slider" ),
+                sliderInputs = $('input.gray'),
+                minGray,
+                textureInfo.info.thresholdIndex_otsu
+            );
+
+            $(document).trigger('opacityBordersChanged', { minGray: minGray, maxGray: textureInfo.info.thresholdIndex_otsu});
+
+        });
+
+        $('input#adjust-yen-thresholding-bottom-controls-container').on('click', function() {
+            console.log(textureInfo.info.thresholdIndex_yen);
+            GenericSlider.setPosSlider(
+                slider = $( "#gray-slider" ),
+                sliderInputs = $('input.gray'),
+                minGray,
+                textureInfo.info.thresholdIndex_yen
+            );
+
+            $(document).trigger('opacityBordersChanged', { minGray: minGray, maxGray: textureInfo.info.thresholdIndex_yen});
+
+        });
+
     }
 }
 
@@ -616,6 +655,8 @@ function initSliders() {
         sliderInputs = $('input.gray'),
         minGray,
         maxGray,
+        minGray,
+        maxGray,
         function(values) {
             $(document).trigger(
                 'opacityBordersChanged',
@@ -655,6 +696,8 @@ function initLayerSliders() {
         sliderInputs = $('input.xlayer'),
         currentVolumeDimension.xmin,
         currentVolumeDimension.xmax,
+        currentVolumeDimension.xmin,
+        currentVolumeDimension.xmax,
         function(values) {
             dimMin = currentVolumeDimension.xmin;
             dimMax = currentVolumeDimension.xmax;
@@ -676,6 +719,8 @@ function initLayerSliders() {
         sliderInputs = $('input.ylayer'),
         currentVolumeDimension.ymin,
         currentVolumeDimension.ymax,
+        currentVolumeDimension.ymin,
+        currentVolumeDimension.ymax,
         function(values) {
             dimMin = currentVolumeDimension.ymin;
             dimMax = currentVolumeDimension.ymax;
@@ -697,6 +742,8 @@ function initLayerSliders() {
         sliderInputs = $('input.zlayer'),
         currentVolumeDimension.zmin,
         currentVolumeDimension.zmax,
+        currentVolumeDimension.zmin,
+        currentVolumeDimension.zmax,
         function(values) {
             dimMin = currentVolumeDimension.zmin;
             dimMax = currentVolumeDimension.zmax;

File diff suppressed because it is too large
+ 0 - 1
static/js/threeJsHelper/dist/threeJsHelper.min.js


+ 47 - 0
static/js/threeJsHelper/src/Application.js

@@ -294,6 +294,45 @@ IPE.app = {
                 }
             });
         });
+
+        $('input#adjust-isodata-thresholding-bottom-controls-container').on('click', function() {
+            console.log(textureInfo.info.thresholdIndex_isodata);
+            GenericSlider.setPosSlider(
+                slider = $( "#gray-slider" ),
+                sliderInputs = $('input.gray'),
+                minGray,
+                textureInfo.info.thresholdIndex_isodata
+            );
+            $(document).trigger('opacityBordersChanged', { minGray: minGray, maxGray: textureInfo.info.thresholdIndex_isodata});
+
+        });
+
+        $('input#adjust-otsu-thresholding-bottom-controls-container').on('click', function() {
+            console.log(textureInfo.info.thresholdIndex_otsu);
+            GenericSlider.setPosSlider(
+                slider = $( "#gray-slider" ),
+                sliderInputs = $('input.gray'),
+                minGray,
+                textureInfo.info.thresholdIndex_otsu
+            );
+
+            $(document).trigger('opacityBordersChanged', { minGray: minGray, maxGray: textureInfo.info.thresholdIndex_otsu});
+
+        });
+
+        $('input#adjust-yen-thresholding-bottom-controls-container').on('click', function() {
+            console.log(textureInfo.info.thresholdIndex_yen);
+            GenericSlider.setPosSlider(
+                slider = $( "#gray-slider" ),
+                sliderInputs = $('input.gray'),
+                minGray,
+                textureInfo.info.thresholdIndex_yen
+            );
+
+            $(document).trigger('opacityBordersChanged', { minGray: minGray, maxGray: textureInfo.info.thresholdIndex_yen});
+
+        });
+
     }
 }
 
@@ -616,6 +655,8 @@ function initSliders() {
         sliderInputs = $('input.gray'),
         minGray,
         maxGray,
+        minGray,
+        maxGray,
         function(values) {
             $(document).trigger(
                 'opacityBordersChanged',
@@ -655,6 +696,8 @@ function initLayerSliders() {
         sliderInputs = $('input.xlayer'),
         currentVolumeDimension.xmin,
         currentVolumeDimension.xmax,
+        currentVolumeDimension.xmin,
+        currentVolumeDimension.xmax,
         function(values) {
             dimMin = currentVolumeDimension.xmin;
             dimMax = currentVolumeDimension.xmax;
@@ -676,6 +719,8 @@ function initLayerSliders() {
         sliderInputs = $('input.ylayer'),
         currentVolumeDimension.ymin,
         currentVolumeDimension.ymax,
+        currentVolumeDimension.ymin,
+        currentVolumeDimension.ymax,
         function(values) {
             dimMin = currentVolumeDimension.ymin;
             dimMax = currentVolumeDimension.ymax;
@@ -697,6 +742,8 @@ function initLayerSliders() {
         sliderInputs = $('input.zlayer'),
         currentVolumeDimension.zmin,
         currentVolumeDimension.zmax,
+        currentVolumeDimension.zmin,
+        currentVolumeDimension.zmax,
         function(values) {
             dimMin = currentVolumeDimension.zmin;
             dimMax = currentVolumeDimension.zmax;

+ 9 - 36
templates/volumes/render.html

@@ -109,12 +109,20 @@
             <div class="left label margin-top">
                 <input type="button" value="control the gray values"/>
             </div>
+
             <div class="control-holder hidden">
                 <span>gray value selection</span>
                 <div id="gray-slider" class="slider"></div>
                 <input id="grayMin" class="gray small-width center" value="" />
                 <input id="grayMax" class="gray small-width center" value="" />
+                <br>
+
+                <input type="button" id="adjust-isodata-thresholding-bottom-controls-container" value="Adjust IsoData's-thresholding"/>
+                <input type="button" id="adjust-otsu-thresholding-bottom-controls-container" value="Adjust Otsu's-thresholding"/>
+                <input type="button" id="adjust-yen-thresholding-bottom-controls-container" value="Adjust Yen's-thresholding"/>
+
             </div>
+
         </div>
 
         <div id="transfer-function-definition" class="controls center">
@@ -196,42 +204,7 @@
     <div id="container-overview" class="float-left">
     </div>
     <div id="bottom-controls-container" class="hidden">
-        <div id="bottom-controls">&nbsp;</div>
+        <div id="bottom-controls">&nbsp;</div>    
         <input type="button" id="hide-bottom-controls-container" value="hide"/>
     </div>
-    {% if ENVIRONMENT == 'staging' %}
-    <!-- Piwik -->
-    <script type="text/javascript">
-        var _paq = _paq || [];
-        _paq.push(['trackPageView']);
-        _paq.push(['enableLinkTracking']);
-        (function() {
-            var u="//piwik.babubabu.de/";
-            _paq.push(['setTrackerUrl', u+'piwik.php']);
-            _paq.push(['setSiteId', 2]);
-            var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
-            g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
-        })();
-    </script>
-    <noscript><p><img src="//piwik.babubabu.de/piwik.php?idsite=2" style="border:0;" alt="" /></p></noscript>
-    <!-- End Piwik Code -->
-    {% endif %}
-
-    {% if ENVIRONMENT == 'prod' %}
-    <!-- Piwik -->
-    <script type="text/javascript">
-        var _paq = _paq || [];
-        _paq.push(['trackPageView']);
-        _paq.push(['enableLinkTracking']);
-        (function() {
-            var u="//piwik.babubabu.de/";
-            _paq.push(['setTrackerUrl', u+'piwik.php']);
-            _paq.push(['setSiteId', 1]);
-            var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
-            g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
-        })();
-    </script>
-    <noscript><p><img src="//piwik.babubabu.de/piwik.php?idsite=1" style="border:0;" alt="" /></p></noscript>
-    <!-- End Piwik Code -->
-    {% endif %}
 {% endblock %}

+ 1 - 1
visualization/settings_env.py.prod.anka

@@ -3,7 +3,7 @@ import os
     define, where this application runs
     prod, staging, dev
 '''
-ENVIRONMENT = 'staging'
+ENVIRONMENT = 'prod'
 
 
 ''' configure more '''

+ 9 - 0
volumes/models.py

@@ -33,6 +33,10 @@ class TextureInfo(EmbeddedDocument):
     slicesPerSprite = IntField()
     numberOfSprites = IntField()
 
+    thresholdIndex_otsu = IntField()
+    thresholdIndex_yen  =  IntField()
+    thresholdIndex_isodata  =  IntField()
+
     @staticmethod
     def from_info_object(infoObject):
         textureInfo = TextureInfo()
@@ -48,6 +52,10 @@ class TextureInfo(EmbeddedDocument):
         textureInfo.frameFrom = infoObject['frameFrom']
         textureInfo.frameTo = infoObject['frameTo']
 
+        textureInfo.thresholdIndex_otsu = infoObject['thresholdIndex_otsu']
+        textureInfo.thresholdIndex_yen  =  infoObject['thresholdIndex_yen']
+        textureInfo.thresholdIndex_isodata = infoObject['thresholdIndex_isodata']
+
         return textureInfo
 
 
@@ -180,6 +188,7 @@ class Volume(Document):
 
         texture = Texture()
         texture.sprites = []
+
         texture.info = TextureInfo.from_info_object(infoObject)
         texture.contenttype = None
         texture.originalSize = originalSize

Some files were not shown because too many files changed in this diff