Esempio n. 1
0
 def lag():
     nonlocal video, audio
     if d['lag'] < 0:
         d['lag'] = 2 * int(translate(abs(d['lag']), 1, 100, 2, 15))
         t = [str(i) for i in range(int(d['lag']))]
         randshuffle(t)
         frameOrder = '|'.join(t)
     else:
         d['lag'] = int(translate(d['lag'], 1, 100, 2, 15)) + 2
         frameOrder = '|'.join([str(v if i % 2 == 0 else d['lag'] - v) for i, v in enumerate(range(d['lag']))])
     video = video.filter("shuffleframes", frameOrder)
Esempio n. 2
0
def yieldImages_ImgLabel(myobj):
    # all the image are substrate by the mean and divided by its std for RGB channel, respectively.
    #mask_process_f = get(myobj.ImageGenerator_Identifier)
    #allDictList = getfileinfo(myobj.datadir, myobj.labelSuffix,myobj.dataExt,myobj.labelExt[0])
    ImgList, ImgNameList = getfilelist(os.path.join(myobj.datadir, myobj.img),
                                       myobj.dataExt)
    #LabelList, LabelNameList =  getfilelist(os.path.join(Imagefolder,'gt'), myobj.labelExt):

    index_list = range(0, len(ImgList))
    randshuffle(index_list)
    for imgindx, thisindex in enumerate(index_list):
        print('processing image {s}'.format(s=imgindx))
        if imgindx == myobj.maximg:
            break

        thisimgfile = ImgList[thisindex]
        thisimgname = ImgNameList[thisindex]

        thismatfile = os.path.join(
            myobj.datadir, myobj.gt,
            thisimgname + myobj.labelSuffix[0] + myobj.labelExt[0])

        #absmatfilelist.append(thismatfile)
        #absfilelist.append(thisimgfile)

        img_org = imread(thisimgfile)  #np.asarray(Image.open(thisimgfile))
        if os.path.isfile(thismatfile):
            mask_org = imread(thismatfile)  #loaded_mt = loadmat(thismatfile)
            mask_org = (mask_org / np.max(mask_org))
        else:
            print(str(thismatfile) + ' does not exist!')
            continue
        filled_img = mask_org

        for resizeratio in myobj.resizeratio:
            #We may only interested in the region inside one region.
            img_res = imresize(img_org, resizeratio)
            mask_res = imresize(mask_org, resizeratio)
            filled_img = imresize(mask_org, resizeratio)
            #crop the boarder image
            [rowsize, colsize] = [img_res.shape[0], img_res.shape[1]]
            row_start = col_start = myobj.boarder * resizeratio
            row_end = rowsize - myobj.boarder * resizeratio
            col_end = colsize - myobj.boarder * resizeratio

            img_res = img_res[row_start:row_end, col_start:col_end, ...]
            mask_res = mask_res[row_start:row_end, col_start:col_end, ...]
            filled_img = filled_img[row_start:row_end, col_start:col_end, ...]
            for rotate_id in myobj.rotatepool:
                if rotate_id == 0:
                    img_rot = img_res
                    mask_rot = mask_res
                else:
                    img_rot = rotate(img_res, rotate_id, mode='nearest')
                    mask_rot = rotate(mask_res, rotate_id, mode='nearest')
                mask = mask_rot
                #assert np.max(mask.flatten()) <= 1, 'please normalize the mask to o, and 1 image'
                img_rgb = img_rot.copy()
                img = pre_process_img(img_rgb, yuv=False)
                # if using special small patch, then crop
                if myobj.crop_patch_size is None:
                    yield img, mask, filled_img
                    #break
                else:
                    if myobj.crop_patch_size[0] <= 1:
                        crop_patch_size = (int(myobj.crop_patch_size[0] * mask.shape[0]), \
                                           int(myobj.crop_patch_size[1] * mask.shape[1]))
                    else:
                        crop_patch_size = myobj.crop_patch_size
                    allcandidates = shuffle(find(mask != np.nan))
                    total_num = len(allcandidates)
                    selected_num = min(myobj.selected_num,
                                       int(myobj.selected_portion * total_num))
                    selected_ind = allcandidates[0:selected_num]

                    Allpatches_vec_img = Points2Patches(
                        selected_ind, img, crop_patch_size)
                    Allpatches_vec_mask = Points2Patches(
                        selected_ind, mask, crop_patch_size)
                    Allpatches_vec_filled_img = Points2Patches(
                        selected_ind, filled_img, crop_patch_size)

                    AllPatches_img = np.reshape(
                        Allpatches_vec_img,
                        (selected_num, ) + crop_patch_size + (img.shape[2], ))
                    AllPatches_mask = np.reshape(
                        Allpatches_vec_mask,
                        (selected_num, ) + crop_patch_size + (mask.shape[2], ))
                    AllPatches_filled_img = np.reshape(
                        Allpatches_vec_filled_img,
                        (selected_num, ) + crop_patch_size + (mask.shape[2], ))
                    # imshow to check if the selected pts is correct.

                    for patch_idx in range(selected_num):
                        #imshow(AllPatches_img[patch_idx, ...])

                        yield AllPatches_img[patch_idx, ...], AllPatches_mask[
                            patch_idx, ...], AllPatches_filled_img[patch_idx,
                                                                   ...]
Esempio n. 3
0
def yieldImages(myobj):
    # all the image are substrate by the mean and divided by its std for RGB channel, respectively.
    mask_process_f = get(myobj.ImageGenerator_Identifier)
    if hasattr(myobj, 'allDictList'):
        allDictList = myobj.allDictList
    else:
        allDictList = getfileinfo(myobj.datadir, myobj.labelSuffix,
                                  myobj.dataExt, myobj.labelExt[0])

    index_list = range(0, len(allDictList))
    rotationlist = myobj.resizeratio
    randshuffle(index_list)
    randshuffle(rotationlist)
    for imgindx, thisindex in enumerate(index_list):
        if imgindx == myobj.maximg:
            break
        returnDict = allDictList[thisindex]
        thismatfile = returnDict['thismatfile']
        thisimgfile = returnDict['thisfile']

        print(thisimgfile)
        img_org = np.asarray(Image.open(thisimgfile))
        loaded_mt = loadmat(thismatfile)
        if type(myobj.contourname) is not list:
            myobj.contourname = [myobj.contourname]
        contour_mat = None
        for contourname in myobj.contourname:
            if contourname in loaded_mt.keys():
                contour_mat = loaded_mt[contourname].tolist()[0]
                break
        if not contour_mat:
            contour_mat = loaded_mt.values()[0].tolist()[0]
            print('check the mat keys, we use the first one default key: ' +
                  loaded_mt.keys()[0])
        outputs_dict = dict()

        for resizeratio in rotationlist:
            img_res = imresize(img_org, resizeratio)
            #print('start mask')
            process_dict = mask_process_f(myobj,
                                          contour_mat,
                                          img_org.shape[0:2],
                                          resizeratio=resizeratio)
            #print('end mask')
            mask_res = process_dict['mask']
            filled_img_res = process_dict[
                'filled_img'] if 'filled_img' in process_dict.keys(
                ) else mask_org
            shed_mask_res = process_dict['shed']

            #We may only interested in the region inside one region.
            #since mask and filled_img are already resized version, only image need to be resized
            #mask_res = mask_org #imresize(mask_org, resizeratio)
            #crop the boarder image
            [rowsize, colsize] = [img_res.shape[0], img_res.shape[1]]
            if myobj.boarder < 1:
                row_board = myobj.boarder * rowsize
                col_board = myobj.boarder * colsize
            elif len(myobj.boarder) == 2:
                row_board, col_board = myobj.boarder
            else:
                row_board = col_board = myobj.boarder

            row_start, col_start = row_board * resizeratio, col_board * resizeratio
            row_end = rowsize - row_board * resizeratio
            col_end = colsize - col_board * resizeratio

            img_res = img_res[row_start:row_end, col_start:col_end, ...]
            mask_res = mask_res[row_start:row_end, col_start:col_end, ...]
            filled_img_res = filled_img_res[row_start:row_end,
                                            col_start:col_end, ...]
            shed_mask_res = shed_mask_res[row_start:row_end, col_start:col_end,
                                          ...]

            if myobj.get_validation == True:
                outputs_dict['img'] = pre_process_img(img_res.copy(),
                                                      yuv=False)
                outputs_dict['mask'] = mask_res
                outputs_dict['filled_img'] = filled_img_res
                outputs_dict['shed_mask'] = shed_mask_res
                yield outputs_dict
                break
            for rotate_id in myobj.rotatepool:
                if rotate_id == 0:
                    img_rot = img_res.copy()
                    mask_rot = mask_res.copy()
                    shed_rot = shed_mask_res.copy()
                    filled_img_rot = filled_img_res.copy()
                else:

                    img_rot = rotate(img_res.copy(),
                                     rotate_id,
                                     mode='reflect',
                                     reshape=False)
                    mask_rot = rotate(mask_res.copy(),
                                      rotate_id,
                                      mode='reflect',
                                      reshape=False)
                    shed_rot = rotate(shed_mask_res.copy(),
                                      rotate_id,
                                      mode='reflect',
                                      reshape=False)
                    filled_img_rot = rotate(filled_img_res.copy(),
                                            rotate_id,
                                            mode='reflect',
                                            reshape=False)

                #assert np.max(mask.flatten()) <= 1, 'please normalize the mask to o, and 1 image'
                img_rot = pre_process_img(img_rot, yuv=False)

                # if using special small patch, then crop
                if myobj.crop_patch_size is None:
                    outputs_dict['img'] = img_rot
                    outputs_dict['mask'] = mask_rot
                    outputs_dict['filled_img'] = filled_img_rot
                    outputs_dict['shed_mask'] = shed_rot
                    for item in first_flip_channel(myobj, outputs_dict):
                        yield item
                #break
                else:
                    if myobj.crop_patch_size[0] <= 1:
                        crop_patch_size = (int(myobj.crop_patch_size[0] * mask_rot.shape[0]), \
                                           int(myobj.crop_patch_size[1] * mask_rot.shape[1]))
                    else:
                        crop_patch_size = myobj.crop_patch_size
                    allcandidates = shuffle(find(mask_rot != np.nan))
                    total_num = len(allcandidates)
                    selected_num = min(myobj.selected_num,
                                       int(myobj.selected_portion * total_num))
                    selected_ind = allcandidates[0:selected_num]

                    Allpatches_vec_img = Points2Patches(
                        selected_ind, img_rot, crop_patch_size)
                    Allpatches_vec_mask = Points2Patches(
                        selected_ind, mask_rot, crop_patch_size)
                    Allpatches_vec_filled_img = Points2Patches(
                        selected_ind, filled_img_rot, crop_patch_size)
                    Allpatches_vec_shed_mask = Points2Patches(
                        selected_ind, shed_rot, crop_patch_size)

                    AllPatches_img = np.reshape(
                        Allpatches_vec_img, (selected_num, ) +
                        crop_patch_size + (img_rot.shape[2], ))
                    AllPatches_mask = np.reshape(
                        Allpatches_vec_mask, (selected_num, ) +
                        crop_patch_size + (mask_rot.shape[2], ))
                    AllPatches_filled_img = np.reshape(
                        Allpatches_vec_filled_img, (selected_num, ) +
                        crop_patch_size + (mask_rot.shape[2], ))
                    AllPatches_shed_mask = np.reshape(
                        Allpatches_vec_shed_mask, (selected_num, ) +
                        crop_patch_size + (mask_rot.shape[2], ))

                    # imshow to check if the selected pts is correct.
                    for patch_idx in range(selected_num):
                        #imshow(AllPatches_img[patch_idx, ...])
                        outputs_dict['img'] = AllPatches_img[patch_idx, ...]
                        outputs_dict['mask'] = AllPatches_mask[patch_idx, ...]
                        outputs_dict['filled_img'] = AllPatches_filled_img[
                            patch_idx, ...]
                        outputs_dict['shed_mask'] = AllPatches_shed_mask[
                            patch_idx, ...]

                        for item in first_flip_channel(myobj, outputs_dict):
                            yield item
Esempio n. 4
0
#	list_1 = []
#	for i in range(n_1):
#		list_1.append('')
#	random.randshuffle(list_1)
#	i = 1
#	for str_1 in list_1:
#		str_11 = str(i) + '、' + list_1[i-1]
#		i = i + 1
#		f.write(str_11)

	f.write('二、教学及课堂\n')
	n_2 = random.randint(3,5)
	list_2 = []
	for i in range(n_2):
		list_2.append('')
	random.randshuffle(list_2)
	i = 1
	for str_2 in list_2:
		str_22 = str(i) + '、' + list_2[i-1] + '\n'
		i = i + 1
		f.write(str_22)
	
	f.write('三、学生考勤和作业和测试情况\n')
	
	f.write('四、学生沟通&家长沟通\n')
	n_4 = random.randint(3,5)
	list_4 = []
	for i in range(n_4):
		list_4.append()
	random.randshuffle(list_4)
	i = 1
Esempio n. 5
0
 def shuffle(self):
     randshuffle(self.tribase_string.tribases)
     self.img = Output.make_img(self.tribase_string.tribases)
     self.output_string = Output.get_output_string(
         self.tribase_string.tribases, self.spiked_codons)