當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。