当前位置: 首页>>代码示例>>Python>>正文


Python ThunderContext.loadImages方法代码示例

本文整理汇总了Python中thunder.ThunderContext.loadImages方法的典型用法代码示例。如果您正苦于以下问题:Python ThunderContext.loadImages方法的具体用法?Python ThunderContext.loadImages怎么用?Python ThunderContext.loadImages使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在thunder.ThunderContext的用法示例。


在下文中一共展示了ThunderContext.loadImages方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: SparkConf

# 需要导入模块: from thunder import ThunderContext [as 别名]
# 或者: from thunder.ThunderContext import loadImages [as 别名]
    # Draw a rectangle around the faces
    for (x, y, w, h) in faces:
        cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), -1)
    return img


# Load images using thundear and pass it to OpenCV haar cascase one by one
if __name__ == "__main__":
    # Define Spark and Thunder context
    conf = SparkConf().setAppName("Collaborative Filter").set("spark.executor.memory", "5g")
    sc = SparkContext(conf=conf)
    tsc = ThunderContext(sc)

    # Load all images in data directory
    data = tsc.loadImages("/home/vj/Desktop/CS-Project/data", inputFormat="png")

    # Loop through each image and convert them to gray
    grayImages = data.apply(lambda (k, v): (k, convertToGray(v)))

    # Loop through all the gray images and find faces
    FaceImages = grayImages.apply(lambda (k, v): (k, detectFaces(v)))
    print (data.dims)
    print (data.nrecords)
    cv2.imshow("image1", grayImages[0])
    cv2.imshow("Face detected1", FaceImages[0])
    cv2.imshow("image2", grayImages[1])
    cv2.imshow("Face detected2", FaceImages[1])
    cv2.imshow("image3", grayImages[2])
    cv2.imshow("Face detected3", FaceImages[2])
    cv2.waitKey(0)
开发者ID:venkatesh369,项目名称:CS-Project,代码行数:32,代码来源:FaceDetect.py

示例2: SparkConf

# 需要导入模块: from thunder import ThunderContext [as 别名]
# 或者: from thunder.ThunderContext import loadImages [as 别名]
# Load thunder
from pyspark import SparkContext, SparkConf
from thunder import Colorize, ThunderContext
image = Colorize.image
import os

#Load Sci-kit image
from skimage.viewer import ImageViewer as skImageViewer

#Load spark context
conf = SparkConf() \
    .setAppName("Display face") \
    .set("spark.executor.memory", "5g")
sc = SparkContext(conf=conf)
#load thunder bolt context
tsc = ThunderContext(sc)

# Load image using thunder
data = tsc.loadImages(os.path.dirname(os.path.realpath(__file__))+'/mush.png',inputFormat='png')
img  = data.first()[1]

# Display image using Sci-kit image
viewer = skImageViewer(img[:,:,0])
viewer.show()
开发者ID:venkatesh369,项目名称:CS-Project,代码行数:26,代码来源:LoadAndDisplayImage.py

示例3: CompressImages

# 需要导入模块: from thunder import ThunderContext [as 别名]
# 或者: from thunder.ThunderContext import loadImages [as 别名]
def CompressImages(inputs, output, confObj):
    debugMode=False
    st=datetime.now()
    imageExt = confObj['ext']
    imageHeight = confObj['dims'][0]
    imageWidth = confObj['dims'][1]
    refImgId = confObj['refImageId']
    diffImageFolder = confObj['DiffImageFolder']

    if debugMode == True:
        print confObj
    
    import glob
    totImages = len(glob.glob(inputs+"*."+imageExt))

    if os.path.exists(output):
        shutil.rmtree(output)
    
    conf = SparkConf().setAppName('ImgCompress')
    sc = SparkContext(conf=conf)
    imageHeight = sc.broadcast(imageHeight)
    imageWidth = sc.broadcast(imageWidth)
    
    tsc = ThunderContext(sc)
    tscImages = tsc.loadImages(inputs, (imageHeight.value,imageWidth.value), imageExt, imageExt).cache()
    
    floatingPixelRdd = tscImages.rdd.flatMapValues(lambda r: r).zipWithIndex().map(lambda l: ((l[0][0],(l[1]-(l[0][0]*int(imageHeight.value)))),l[0][1]))\
        .flatMapValues(lambda r: r).zipWithIndex().\
        map(lambda l: ((l[0][0][1],(l[1]-(l[0][0][0]*int(imageWidth.value)*int(imageHeight.value) + l[0][0][1]*int(imageWidth.value)))),(l[0][0][0],l[0][1])))
    
    if debugMode == True:
        floatingPixelRdd.saveAsTextFile(output+"\\Stage-1-FloatingPixel")    
    
    temporalVoxelRdd = floatingPixelRdd.groupByKey().map(lambda x : (x[0], list(x[1]))).cache()
    if debugMode == True:
        temporalVoxelRdd.saveAsTextFile(output+"\\Stage-2-TemporalVoxel")    
    
    iMapImageDict = {}
    for imgIndex in range(totImages):
        imgIndexBD = sc.broadcast(imgIndex)
        
        #-------------------------------HELPER FUNCTIONS-------------------------------------
        def ReAdjustImapList(l):
            intList = l[1]
            mKey = intList.pop(imgIndexBD.value)[1]
            return (mKey, intList)

        def calculateMedainForEachImage(l):
            intRdd = sc.parallelize(l[1]).flatMap(lambda l: l).groupByKey().map(lambda x : (x[0], list(x[1])))
            intRddSorted = intRdd.map(lambda l: (l[0],sorted(l[1])))
            intRddMedian = intRddSorted.map(lambda l: (l[0], l[1][int(len(l[1])/2)])) 
            return intRddMedian.collect()
        #-------------------------------HELPER FUNCTIONS-------------------------------------
        
        
        imapRdd = temporalVoxelRdd.map(lambda l: ReAdjustImapList(l)).sortBy(lambda  l: l[0], False)\
            .groupByKey().map(lambda x : (x[0], list(x[1])))
        if debugMode == True:
            imapRdd.saveAsTextFile(output+"\\Stage-3__IMAP-Stage-1_imgIdx-" + str(imgIndex))    

        
        imapRdd = imapRdd.flatMapValues(lambda l: l).flatMapValues(lambda l: l).map(lambda l: ((l[0],l[1][0]),l[1][1])).\
            groupByKey().map(lambda x : (x[0], list(x[1]))).\
            map(lambda l: (l[0],sorted(l[1]))).map(lambda l: (l[0], l[1][int(len(l[1])/2)])).\
            map(lambda l: (l[0][0],(l[0][1], l[1])))
        if debugMode == True:
            imapRdd.saveAsTextFile(output+"\\Stage-3__IMAP-Stage-2_imgIdx-" + str(imgIndex))    
        
        imapRdd = imapRdd.groupByKey().map(lambda x : (x[0], sorted(list(x[1]),key = lambda k: k[0])))
        if debugMode == True:
            imapRdd.saveAsTextFile(output+"\\Stage-3__IMAP-Stage-3_imgIdx-" + str(imgIndex))    

        imapDict = imapRdd.collectAsMap()
        iMapImageDict[imgIndex] = imapDict  

        
    iMapDictBD = sc.broadcast(iMapImageDict)
    
    refImageIdBD=sc.broadcast(refImgId)
    
    def CalcMapValue(pix, iMapVal):
        pImgIdx = pix[0]
        residual=0
        for iIdx in iMapVal:
            if pImgIdx == iIdx[0]:
                residual = int(iIdx[1])  - pix[1]
                break
        return (pix[0], residual)
        
        
    def ApplyIMap(l):
        voxel = l[1]
        refIntensity = l[1][refImageIdBD.value][1]
        iMapValues= iMapDictBD.value[refImageIdBD.value][refIntensity]
        resdualValues=[]
        for pixel in voxel:
            if pixel[0] != refImageIdBD.value:
                resdualValues.append( CalcMapValue(pixel, iMapValues) )
            else:
                resdualValues.append( pixel )
#.........这里部分代码省略.........
开发者ID:vivek-trivedi,项目名称:ImageSetCompression,代码行数:103,代码来源:ImageSetCompression.py


注:本文中的thunder.ThunderContext.loadImages方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。