def analyseData(dd): #ss = dd.sum(0) #dnp.plot.image(ss) ##ss is the flat field print "Calculating median for the dataset ..." med = dnp.median(dd, 0) print "Median calculated" if plotData: dnp.plot.image(med) sleep(2) #flatFieldCorrectedSum = ss/med #dnp.plot.image(flatFieldCorrectedSum) xVals = [] yVals = [] ## print "Calculating centroid ..." centroids = [] for i in range(18): #dnp.plot.image(dd[i, :, :] / med) im = dd[i, :, :] / med im = javaImage.medianFilter(im, [3, 3]) im = dnp.array(im) threshold = 0.85 if plotData: dnp.plot.image(im) if plotData: sleep(1) if plotData: dnp.plot.image(im < threshold) if plotData: sleep(1) cent = dnp.centroid(im < threshold) yVals.append(cent[0]) xVals.append(cent[1]) centroids.append(cent) print "y:" + ` yVals ` print('') print "x:" + ` xVals ` #help(dnp.fit.ellipsefit) if plotData: dnp.plot.line(dnp.array(xVals), dnp.array(yVals)) ellipseFitValues = dnp.fit.ellipsefit(xVals, yVals) print "major: " + ` ellipseFitValues[0] ` print "minor semi-axis: " + ` ellipseFitValues[1] ` print "major axis angle: " + ` ellipseFitValues[2] ` print "centre co-ord 1: " + ` ellipseFitValues[3] ` print "centre co-ord 2: " + ` ellipseFitValues[4] ` print "centroids:" + ` centroids ` xOffset = getXOffset(ellipseFitValues[1], ellipseFitValues[0]) zOffset = getZOffset(ellipseFitValues[2]) return xOffset, zOffset, centroids, ellipseFitValues
def threshold_global(image, threshold, down=True): '''Applies a global threshold across the whole image. If 'down' is true, then pixels with values <= to 'threshold' are set to 1 and the others set to 0. If 'down' is false, then pixels with values >= to 'threshold' are set to 1 and the others set to 0.''' return _image.globalThreshold(image, threshold, down)
def threshold_global_mean(image, down=True): '''Applies a global mean threshold across the whole image with the mean pixel intensity value as a threshold value''' return _image.globalMeanThreshold(image, down)
def findshift(a, b, rect=None): '''Find translation vector from b to a using rectangular ROI rect''' return _image.findTranslation2D(a, b, rect._jroi())
def extract_blob(image, rule=8): '''Given a binary image, connect together pixels to form blobs/clusters using the specified connectivity rule (can be 4 or 8, set to 8 by default). The found blobs will be labeled in an output image and also described as a set of contours.''' return _image.extractBlob(image, rule)
# Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ### ''' Image processing package ''' import org.eclipse.dawnsci.analysis.dataset.impl.Image as _image import uk.ac.diamond.scisoft.analysis.dataset.function.MapToShiftedCartesian as _mapshift from jycore import _wrap #import ImageFilterServiceCreator and instanciate it import org.dawnsci.boofcv.BoofCVImageFilterServiceCreator as _creator _image.setImageFilterService(_creator.createFilterService()) @_wrap def findshift(a, b, rect=None): '''Find translation vector from b to a using rectangular ROI rect''' return _image.findTranslation2D(a, b, rect._jroi()) @_wrap def shiftimage(image, shift): '''Translate an image by specified shift''' sfn = _mapshift(shift[0], shift[1]) return sfn.value([image])[0]
def threshold_adaptive_gaussian(image, radius, down=True): '''Thresholds the image using an adaptive threshold that is computed using a local square region centered on each pixel. The threshold is equal to the gaussian weighted sum of the surrounding pixels plus the bias. If down is true then b(x,y) = I(x,y) <= T(x,y) + bias ? 1 : 0. Otherwise b(x,y) = I(x,y) >= T(x,y) + bias ? 0 : 1''' return _image.adaptiveGaussianThreshold(image, radius, down)
def threshold_global_otsu(image, down=True): '''Applies a global mean threshold across the whole image with the variance based threshold using Otsu's method''' return _image.globalOtsuThreshold(image, down)
def threshold_global_entropy(image, down=True): '''Applies a global mean threshold across the whole image with the threshold which maximizes the entropy between the foreground and background regions.''' return _image.globalEntropyThreshold(image, down)
def findshift(a, b, rect=None): '''Find translation vector from b to a using rectangular ROI rect''' if rect is not None: rect = rect._jroi() return _image.findTranslation2D(a, b, rect)
def threshold_adaptive_sauvola(image, radius, down=True): '''Applies Sauvola thresholding to the input image. Intended for use with text image''' return _image.adaptiveSauvolaThreshold(image, radius, down)
def extract_blob(image, rule = 8): '''Given a binary image, connect together pixels to form blobs/clusters using the specified connectivity rule (can be 4 or 8, set to 8 by default). The found blobs will be labeled in an output image and also described as a set of contours.''' return _image.extractBlob(image, rule)
# distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ### ''' Image processing package ''' import org.eclipse.dawnsci.analysis.dataset.impl.Image as _image import uk.ac.diamond.scisoft.analysis.dataset.function.MapToShiftedCartesian as _mapshift from jycore import _wrap #import ImageFilterServiceCreator and instanciate it import org.dawnsci.boofcv.BoofCVImageFilterServiceCreator as _creator _image.setImageFilterService(_creator.createFilterService()) @_wrap def findshift(a, b, rect=None): '''Find translation vector from b to a using rectangular ROI rect''' return _image.findTranslation2D(a, b, rect._jroi()) @_wrap def shiftimage(image, shift): '''Translate an image by specified shift''' sfn = _mapshift(shift[0], shift[1]) return sfn.value([image])[0] import uk.ac.diamond.scisoft.analysis.dataset.function.BicubicInterpolator as _bicubic