예제 #1
0
def get_image_bandpass(request):
    """
    Function to get the computing image with a fourier filter applied
    """
    imagePath = request.GET.get('image', None)
    lowFreq = request.GET.get('lowFreq', 0.)
    highFreq = request.GET.get('highFreq', 1.0)
    decay = request.GET.get('decayFreq', 0.)
    dim = request.GET.get('dim', None)
    
#    ** DEBUG **
#    print str(imagePath)
#    print float(lowFreq)
#    print float(highFreq)
#    print float(decay)
#    print int(dim)
    
    # create a xmipp image empty
    imgXmipp = xmipp.Image()
    
    # compute the Fourier Filter in the image
    xmipp.bandPassFilter(imgXmipp, str(imagePath), float(lowFreq), float(highFreq), float(decay), int(dim))
    
    # from PIL import Image
    img = getPILImage(imgXmipp, dim)
        
    response = HttpResponse(mimetype="image/png")
    img.save(response, "PNG")
    
    return response
예제 #2
0
def get_image_psd(request):
    """
    Function to get the computing psd image
    """
    imagePath = request.GET.get('image', None)
    downsample = request.GET.get('downsample', None)
    dim = request.GET.get('dim', None)
    
    # create a xmipp image empty
    imgXmipp = xmipp.Image()

    #    ** DEBUG **
#    print str(imagePath)
#    print float(downsample) 
#    print int(dim)

    # compute the PSD image
    xmipp.fastEstimateEnhancedPSD(imgXmipp, str(imagePath), 
                                  float(downsample), int(dim), 2)
    
    # from PIL import Image
    img = getPILImage(imgXmipp, dim)
       
    response = HttpResponse(mimetype="image/png")
    img.save(response, "PNG")
    return response
예제 #3
0
 def generateMicImage(self, input_file, output_file=None):
     if not output_file:
         output_file = os.path.splitext(input_file)[0] + '.png'
     img = ImageHandler().createImage()
     img.read(input_file)
     pimg = getPILImage(img)
     pwutils.makeFilePath(output_file)
     pimg.save(output_file, "PNG")
예제 #4
0
def get_image_mask(request):
    """
    Function to get the computing image with a mask filter applied
    """
    imagePath = request.GET.get('image', None)
    dim = request.GET.get('dim', None)
    
    # create a xmipp image empty
    imgXmipp = xmipp.Image()
    
    # from PIL import Image
    img = getPILImage(imgXmipp, dim)
        
    response = HttpResponse(mimetype="image/png")
    img.save(response, "PNG")
    return response
예제 #5
0
def get_slice(request):
    sliceNo = None
    imagePath = request.GET.get('image')
    imageDim = request.GET.get('dim', 150)
    mirrorY = 'mirrorY' in request.GET
    #    applyTransformMatrix = 'applyTransformMatrix' in request.GET
    #    onlyApplyShifts = request.GET.get('onlyApplyShifts',False)
    #    wrap = request.GET.get('wrap',False)
    #    transformMatrix = request.GET.get('transformMatrix',None)

    # This validations not works for volumes into a stack
    if '__slice__' in imagePath:
        parts = imagePath.split('__slice__', 1)
        sliceNo = int(parts[0])
        imagePath = parts[1]

#     if '@' in imagePath:
#             parts = imagePath.split('@')
#             imageNo = parts[0]
#             imagePath = parts[1]
    imagePath = convertVolume(request, imagePath)
    imgXmipp = xmipp.Image()
    if sliceNo is None:
        imgXmipp.readPreview(imagePath, int(imageDim))
    else:
        imgXmipp.readPreview(imagePath, int(imageDim), sliceNo)

#        if applyTransformMatrix and transformMatrix != None:
#            imgXmipp.applyTransforMatScipion(transformMatrix, onlyApplyShifts, wrap)
#
    if mirrorY:
        imgXmipp.mirrorY()

    # from PIL import Image


#   img = getPILImage(imgXmipp, None, False)
    img = getPILImage(imgXmipp, normalize=False)
    response = HttpResponse(mimetype="image/png")

    if img.mode != 'RGB':
        img = img.convert('RGB')
    img.save(response, "PNG")

    return response
예제 #6
0
def get_slice(request):
    sliceNo = None
    imagePath = request.GET.get('image')
    imageDim = request.GET.get('dim', 150)
    mirrorY = 'mirrorY' in request.GET
#    applyTransformMatrix = 'applyTransformMatrix' in request.GET
#    onlyApplyShifts = request.GET.get('onlyApplyShifts',False)
#    wrap = request.GET.get('wrap',False)
#    transformMatrix = request.GET.get('transformMatrix',None)


    # This validations not works for volumes into a stack
    if '__slice__' in imagePath:
        parts = imagePath.split('__slice__', 1)
        sliceNo = int(parts[0])
        imagePath = parts[1]
        
#     if '@' in imagePath:
#             parts = imagePath.split('@')
#             imageNo = parts[0]
#             imagePath = parts[1]
    imagePath = convertVolume(request, imagePath)
    imgXmipp = xmipp.Image()
    if sliceNo is None:
        imgXmipp.readPreview(imagePath, int(imageDim))
    else:
        imgXmipp.readPreview(imagePath, int(imageDim), sliceNo)
        
#        if applyTransformMatrix and transformMatrix != None: 
#            imgXmipp.applyTransforMatScipion(transformMatrix, onlyApplyShifts, wrap)
#        
    if mirrorY: 
        imgXmipp.mirrorY()
    
    # from PIL import Image
#   img = getPILImage(imgXmipp, None, False)
    img = getPILImage(imgXmipp, normalize=False)
    response = HttpResponse(mimetype="image/png")
    
    if img.mode != 'RGB':
        img = img.convert('RGB')
    img.save(response, "PNG")
    
    return response
예제 #7
0
def get_image_gaussian(request):
    """
    Function to get the computing image with a gaussian filter applied
    """
    imagePath = request.GET.get('image', None)
    freqSigma = request.GET.get('sigmaFreq', None)
    dim = request.GET.get('dim', None)
    
    # create a xmipp image empty
    imgXmipp = xmipp.Image()
    
    # compute the Gaussian Filter in the image
    xmipp.gaussianFilter(imgXmipp, str(imagePath), float(freqSigma), int(dim))
    # from PIL import Image
    img = getPILImage(imgXmipp, dim)
        
    response = HttpResponse(mimetype="image/png")
    img.save(response, "PNG")
    return response
예제 #8
0
    def generate_image(self, input_file, outputName=None):
        output_root = join(self.images_path, basename(outputName))
        output_file = output_root + '.jpg'

        print "Generating image: ", output_file

        if not exists(output_file):
            from PIL import Image
            self.img.read(join(self.project_path, input_file))
            pimg = getPILImage(self.img)

            pwutils.makeFilePath(output_file)
            if self.bigThumb:
                pimg.save(output_file, "JPEG")

            if self.smallThumb:
                pimg.thumbnail((self.smallThumb, self.smallThumb), Image.ANTIALIAS)
                pimg.save(output_root + 't.jpg', "JPEG")

        return output_file
예제 #9
0
    def generate_image(self, input_file, outputName=None):
        output_root = join(self.images_path, basename(outputName))
        output_file = output_root + '.png'

        print "Generating image: ", output_file

        if not exists(output_file):
            from PIL import Image
            self.img.read(join(self.project_path, input_file))
            pimg = getPILImage(self.img)

            pwutils.makeFilePath(output_file)
            if self.bigThumb:
                pimg.save(output_file, "PNG")

            if self.smallThumb:
                pimg.thumbnail((self.smallThumb, self.smallThumb), Image.ANTIALIAS)
                pimg.save(output_root + 't.png', "PNG")

        return output_file
예제 #10
0
def get_image(request):
    imageNo = None
    
    # TO DO: Change the way to obtain the separate string of the imagePath
    imagePath = request.GET.get('image')
    imageDim = request.GET.get('dim', 150)

    # This prefix can be passed to avoid that image is not refresh when cached by browser (name does not change)
    prefix = request.GET.get('prefix', "")
    
    mirrorY = 'mirrorY' in request.GET
    
    applyTransformMatrix = 'applyTransformMatrix' in request.GET
    onlyShifts = 'onlyShifts' in request.GET
    wrap = 'wrap' in request.GET
     
    matrix = request.GET.get('matrix',None)
        
    try:
        # PAJM: Como vamos a gestionar lsa imagen    
        if imagePath.endswith('png') or imagePath.endswith('gif'):
            imagePathTmp = os.path.join(request.session['projectPath'], prefix + imagePath)
            img = getImage(imagePathTmp, tkImage=False)
        else:
            if '@' in imagePath:
                parts = imagePath.split('@')
                imageNo = parts[0]
                imagePath = parts[1]
    
            if 'projectPath' in request.session:
                imagePathTmp = os.path.join(request.session['projectPath'], imagePath)
                if not os.path.isfile(imagePathTmp):
                    raise Exception('should not use getInputPath')
                    #imagePath = getInputPath('showj', imagePath)      
    
            if imageNo:
                imagePath = '%s@%s' % (imageNo, imagePath) 
                
            imgXmipp = xmipp.Image()
            imgXmipp.readPreview(imagePath, int(imageDim))
            
            #===================================================================
            # Transform Matrix
            if applyTransformMatrix: 
                takarras=[tMatrix[0][0], tMatrix[0][1], tMatrix[0][2], x if x!=None else 0,
                tMatrix[1][0], tMatrix[1][1], tMatrix[1][2], y if y!=None else 0,
                tMatrix[2][0], tMatrix[2][1], tMatrix[2][2], z if z!=None else 0]
#               imgXmipp.applyTransforMatScipion(matrix, onlyShifts, wrap)
                imgXmipp.applyTransforMatScipion(takarras, onlyShifts, wrap)
            #===================================================================
            
            #===================================================================
            # Invert Y axis
            if mirrorY: 
                imgXmipp.mirrorY()
            #===================================================================
            
            #TO DO: PSD FIX
            if imagePath.endswith('.psd'):
                imgXmipp.convertPSD()
            
            # from PIL import Image
            img = getPILImage(imgXmipp, None)
    except Exception:
        img = getImage(findResource(getResourceIcon("no_image")), tkImage=False)


    response = HttpResponse(mimetype="image/png")
    img.save(response, "PNG")
    return response
예제 #11
0
def get_image(request):
    imageNo = None

    # TO DO: Change the way to obtain the separate string of the imagePath
    imagePath = request.GET.get('image')
    imageDim = request.GET.get('dim', 150)

    # This prefix can be passed to avoid that image is not refresh when cached by browser (name does not change)
    prefix = request.GET.get('prefix', "")

    mirrorY = 'mirrorY' in request.GET

    applyTransformMatrix = 'applyTransformMatrix' in request.GET
    onlyShifts = 'onlyShifts' in request.GET
    wrap = 'wrap' in request.GET

    matrix = request.GET.get('matrix', None)

    try:
        # PAJM: Como vamos a gestionar lsa imagen
        if imagePath.endswith('png') or imagePath.endswith('gif'):
            imagePathTmp = os.path.join(request.session['projectPath'],
                                        prefix + imagePath)
            img = getImage(imagePathTmp, tkImage=False)
        else:
            if '@' in imagePath:
                parts = imagePath.split('@')
                imageNo = parts[0]
                imagePath = parts[1]

            if 'projectPath' in request.session:
                imagePathTmp = os.path.join(request.session['projectPath'],
                                            imagePath)
                if not os.path.isfile(imagePathTmp):
                    raise Exception('should not use getInputPath')
                    #imagePath = getInputPath('showj', imagePath)

            if imageNo:
                imagePath = '%s@%s' % (imageNo, imagePath)

            imgXmipp = xmipp.Image()
            imgXmipp.readPreview(imagePath, int(imageDim))

            #===================================================================
            # Transform Matrix
            if applyTransformMatrix:
                takarras = [
                    tMatrix[0][0], tMatrix[0][1], tMatrix[0][2],
                    x if x != None else 0, tMatrix[1][0], tMatrix[1][1],
                    tMatrix[1][2], y if y != None else 0, tMatrix[2][0],
                    tMatrix[2][1], tMatrix[2][2], z if z != None else 0
                ]
                #               imgXmipp.applyTransforMatScipion(matrix, onlyShifts, wrap)
                imgXmipp.applyTransforMatScipion(takarras, onlyShifts, wrap)
            #===================================================================

            #===================================================================
            # Invert Y axis
            if mirrorY:
                imgXmipp.mirrorY()
            #===================================================================

            #TO DO: PSD FIX
            if imagePath.endswith('.psd'):
                imgXmipp.convertPSD()

            # from PIL import Image
            img = getPILImage(imgXmipp, None)
    except Exception:
        img = getImage(findResource(getResourceIcon("no_image")),
                       tkImage=False)

    response = HttpResponse(mimetype="image/png")
    img.save(response, "PNG")
    return response