示例#1
0
 def setup_peak_search_algorithm(self, algorithm, mask=None):
     # init the peak search algorithm
     if algorithm == 'Massif':
         self.peak_search_algorithm = Massif(self.img_data.img_data)
     elif algorithm == 'Blob':
         if mask is not None:
             self.peak_search_algorithm = BlobDetection(
                 self.img_data.img_data * mask)
         else:
             self.peak_search_algorithm = BlobDetection(
                 self.img_data.img_data)
         self.peak_search_algorithm.process()
     else:
         return
示例#2
0
 def test_local_max(self):
     bd = BlobDetection(self.img)
     bd._one_octave(shrink=False, refine=False, n_5=False)
     self.assert_(numpy.alltrue(_blob.local_max(bd.dogs, bd.cur_mask, False) == \
                                      local_max(bd.dogs, bd.cur_mask, False)), "max test, 3x3x3")
     self.assert_(numpy.alltrue(_blob.local_max(bd.dogs, bd.cur_mask, True) == \
                                      local_max(bd.dogs, bd.cur_mask, True)), "max test, 3x5x5")
示例#3
0
    def setup_peak_search_algorithm(self, algorithm, mask=None):
        """
        Initializes the peak search algorithm on the current image
        :param algorithm:
            peak search algorithm used. Possible algorithms are 'Massif' and 'Blob'
        :param mask:
            if a mask is used during the process this is provided here as a 2d array for the image.
        """

        if algorithm == 'Massif':
            self.peak_search_algorithm = Massif(self.img_model.raw_img_data)
        elif algorithm == 'Blob':
            if mask is not None:
                self.peak_search_algorithm = BlobDetection(self.img_model.raw_img_data * mask)
            else:
                self.peak_search_algorithm = BlobDetection(self.img_model.raw_img_data)
            self.peak_search_algorithm.process()
        else:
            return
示例#4
0
__author__ = 'Clemens Prescher'

from pyFAI.blob_detection import BlobDetection
from Data.ImgData import ImgData
import numpy as np
import pylab

img_data = ImgData()
# img_data.load('/Users/Doomgoroth/Programming/Large Projects/Dioptas/Testing/pyFAITest/17_LaB6_dc300-00000.tif')
img_data.load(
    '/Users/Doomgoroth/Programming/Large Projects/Dioptas/Testing/pyFAITest/LaB6_WOS_30keV_005.tif'
)
bd = BlobDetection(np.log1p(img_data.get_img_data()))

bd.process()

x = []
y = []
int = []
sigma = []

print bd.keypoints.__len__()
for j in range(bd.keypoints.__len__()):
    k = bd.keypoints[j]
    int.append(k[2])
    sigma.append(k[3])
    if sigma[-1] > 0.25:
        x.append(k[0])
        y.append(k[1])

pylab.hist(int)
示例#5
0
文件: blob.py 项目: coquellen/pyFAI
                                                               reshape=False)
    return im


if len(UtilsTest.options.args) > 0:
    data = fabio.open(UtilsTest.options.args[0]).data
    if len(UtilsTest.options.args) > 1:
        msk = fabio.open(UtilsTest.options.args[1]).data
    else:
        msk = None
else:
    data = image_test_rings()
    msk = None

bd = BlobDetection(
    data, mask=msk
)  # , cur_sigma=0.25, init_sigma=numpy.sqrt(2)/2, dest_sigma=numpy.sqrt(2), scale_per_octave=2)

pylab.ion()
f = pylab.figure(1)
ax = f.add_subplot(111)
ax.imshow(numpy.log1p(data), interpolation='nearest')

for i in range(5):
    print('Octave #%i' % i)
    bd._one_octave(shrink=True, refine=True, n_5=False)
    print("Octave #%i Total kp: %i" % (i, bd.keypoints.size))

# bd._one_octave(False, True ,False)

print('Final size of keypoints : %i' % bd.keypoints.size)
示例#6
0
    def search_peaks_on_ring(self,
                             peak_index,
                             delta_tth=0.1,
                             algorithm='Massif',
                             min_mean_factor=1,
                             upper_limit=55000):
        if not self.is_calibrated:
            return

        #transform delta from degree into radians
        delta_tth = delta_tth / 180.0 * np.pi

        # get appropiate two theta value for the ring number
        tth_calibrant_list = self.calibrant.get_2th()
        tth_calibrant = np.float(tth_calibrant_list[peak_index])
        print tth_calibrant

        # get the calculated two theta values for the whole image
        if self.geometry._ttha is None:
            tth_array = self.geometry.twoThetaArray(
                self.img_data.img_data.shape)
        else:
            tth_array = self.geometry._ttha

        # create mask based on two_theta position
        mask = abs(tth_array - tth_calibrant) <= delta_tth

        # init the peak search algorithm
        if algorithm == 'Massif':
            peak_search_algorithm = Massif(self.img_data.img_data)
        elif algorithm == 'Blob':
            peak_search_algorithm = BlobDetection(self.img_data.img_data *
                                                  mask)
            peak_search_algorithm.process()
        else:
            return

        # calculate the mean and standard deviation of this area
        sub_data = np.array(self.img_data.img_data.ravel()[np.where(
            mask.ravel())],
                            dtype=np.float64)
        sub_data[np.where(sub_data > upper_limit)] = np.NaN
        mean = np.nanmean(sub_data)
        std = np.nanstd(sub_data)

        # set the threshold into the mask (don't detect very low intensity peaks)
        threshold = min_mean_factor * mean + std
        mask2 = np.logical_and(self.img_data.img_data > threshold, mask)
        mask2[np.where(self.img_data.img_data > upper_limit)] = False
        size2 = mask2.sum(dtype=int)

        keep = int(np.ceil(np.sqrt(size2)))
        try:
            res = peak_search_algorithm.peaks_from_area(mask2,
                                                        Imin=mean - std,
                                                        keep=keep)
        except IndexError:
            res = []

        # Store the result
        if len(res):
            self.points.append(np.array(res))
            self.points_index.append(peak_index)