Example #1
0
def main():
    dir_train = "./2019Proj1_train/"
    dir_labeled_train = "./labeled_train/"

    if not os.path.exists(dir_labeled_train):
        os.makedirs(dir_labeled_train)

    filelist = os.listdir(dir_train)
    num_file = len(filelist)

    startIdx = 0
    endIdx = num_file - 1
    if len(sys.argv) > 1 and sys.argv[1].isdigit():
        startIdx = int(sys.argv[1])

    if len(sys.argv) > 2 and sys.argv[2].isdigit():
        endIdx = int(sys.argv[2])

    print(endIdx)
    for i in range(max(0, startIdx), min(num_file - 1, endIdx) + 1):
        filename = filelist[i]
        name, extension = os.path.splitext(filename)
        image = Image.open(dir_train + filename)

        plt.title("Labeling: " + str(i) + ". " + name)
        plt.imshow(image)
        roi = RoiPoly(color='r')

        # show result
        plt.title("Result: " + str(i) + ". " + name)
        plt.imshow(image)
        roi.display_roi()
        plt.show()

        # get mask
        imgSize = np.shape(image)
        mask = roi.get_mask(np.zeros(imgSize[0:2], dtype=bool))

        # show mask
        # plt.title("Mask: " + str(i) + ". " + name)
        # plt.imshow(mask)
        # plt.show()

        np.save(os.path.join(dir_labeled_train, name + '.npy'), mask)
        print("Finish labeling: " + dir_labeled_train + name + '.npy')
        plt.close()
    # # Let user draw third ROI
    # roi3 = RoiPoly(color='r', fig=fig)
    #
    # # Show the image
    # fig = plt.figure()
    # plt.imshow(I1, interpolation='nearest')
    # plt.title('Image %i, draw fourth ROI' %i)
    # plt.show(block=False)

    # # Let user draw fourth ROI
    # roi4 = RoiPoly(color='b', fig=fig)
    #
    # # Show the image with both ROIs
    # plt.imshow(I1, interpolation='nearest')
    # [x.display_roi() for x in [roi1, roi2, roi3, roi4]]
    roi1.display_roi()
    plt.title('All ROIs')
    plt.show()

    mask1 = roi1.get_mask(gray)
    # mask2 = roi2.get_mask(gray)
    # mask3 = roi3.get_mask(gray)
    # mask4 = roi4.get_mask(gray)

    # Show ROI masks
    plt.imshow(mask1, interpolation='nearest', cmap='Greys')
    plt.title('ROI mask')
    plt.show()
    # plt.imshow(mask1 + mask2 + mask3 + mask4, \
    #            interpolation='nearest', cmap="Greys")
    # plt.title('ROI masks of the ROIs')
if __name__ == '__main__':
    results = multiprocessing.Queue()

    # configure below for your experiment
    detectorName = 'MPCCD-8N0-3-002-6'
    integrateOver = 10
    t0offset = -10

    fig = plt.figure()
    tenFrames, curTag = returnTenFrames(detectorName,
                                        integrateOver=integrateOver)
    plt.imshow(tenFrames)
    my_roi = RoiPoly(color='r', fig=fig)
    plt.imshow(tenFrames)
    my_roi.display_roi()
    mask = my_roi.get_mask(tenFrames)

    #binning parameters
    roiBins = 40
    startBin = -2.0
    endbin = 3.0
    binCounterBin = np.zeros(roiBins)

    binTheData = binROI(results, detectorName, curTag, startBin, endbin, mask,
                        roiBins, t0offset)
    binTheData.start()
    binROIs = np.zeros(roiBins)
    bin_nomDel = np.zeros(roiBins)
    i0det = 0
    beamStatus = 0
Example #4
0
# Show the image
fig = plt.figure()
plt.imshow(img, interpolation='nearest', cmap="Greys")
plt.colorbar()
plt.title("left click: line segment         right click or double click: close region")
plt.show(block=False)

# Let user draw first ROI
roi1 = RoiPoly(color='r', fig=fig)

# Show the image with the first ROI
fig = plt.figure()
plt.imshow(img, interpolation='nearest', cmap="Greys")
plt.colorbar()
roi1.display_roi()
plt.title('draw second ROI')
plt.show(block=False)

# Let user draw second ROI
roi2 = RoiPoly(color='b', fig=fig)

# Show the image with both ROIs and their mean values
plt.imshow(img, interpolation='nearest', cmap="Greys")
plt.colorbar()
for roi in [roi1, roi2]:
    roi.display_roi()
    roi.display_mean(img)
plt.title('The two ROIs')
plt.show()
Example #5
0
def main():

    # logging.basicConfig(format='%(levelname)s ''%(processName)-10s : %(asctime)s ','%(module)s.%(funcName)s:%(lineno)s %(message)s',level=logging.INFO)

    # load images
    data_path  = '/home/pratique/drone-course/Window_detection/GMM/daylight_100'
    reply = 'k'
    i = 0
    for filename in os.listdir(data_path):
        # print filename
        if i%10 != 0:
            i+=1
            continue
        img = cv2.imread(os.path.join(data_path,filename))
        # convert = tune_RGB(img)
    	#convert = tune_HSV(img)
    	convert = adjust_gamma(img, gamma = 1.5)
    	# convert = cv2.fastNlMeansDenoisingColored(convert, None, 3, 3, 7, 15)
        convert = cv2.medianBlur(convert,5)
        img = cv2.cvtColor(convert,cv2.COLOR_BGR2RGB)
        # Show the image
        # Show the image
        # img = img[:,:,[2,1,0]]
        fig = plt.figure()
        plt.imshow(img, interpolation='nearest', cmap="Greys")
        plt.colorbar()
        plt.title("left click: line segment         right click or double click: close region")
        plt.show(block=False)

        # Let user draw first ROI
        roi1 = RoiPoly(color='r', fig=fig)

        # Show the image with the first ROI
        fig = plt.figure()
        plt.imshow(img, interpolation='nearest', cmap="Greys")
        plt.colorbar()
        roi1.display_roi()
        plt.title('draw second ROI')
        plt.show(block=False)

        # Let user draw second ROI
        roi2 = RoiPoly(color='b', fig=fig)

        # Show the image with both ROIs and their mean values
        plt.imshow(img, interpolation='nearest', cmap="Greys")
        plt.colorbar()
        for roi in [roi1, roi2]:
            roi.display_roi()
            roi.display_mean(img)
        plt.title('The two ROIs')
        plt.show()

        # plt.imshow(np.bitwise_not(roi2.get_mask(img) ^ roi1.get_mask(img)),
        #            interpolation='nearest', cmap="Greys")
        # plt.title('ROI masks of the two ROIs')
        # plt.show()

        #store data
        mask = roi2.get_mask(img) ^ roi1.get_mask(img)
        mask.astype(int)
        # print(np.uint8(mask))
        window_mask = np.uint8(mask*255) 
        extracted_frame = cv2.bitwise_and(img, img, mask = window_mask)
        extracted_frame = cv2.cvtColor(extracted_frame,cv2.COLOR_RGB2BGR)
        # input('aa')
        cv2.imwrite("./data/window_100"+str(i)+".jpg", extracted_frame)
        i = i+1
        if 0xFF == ord('q'):
            break
Example #6
0
        l_mouse_mask = np.load(l_mask_file)
        if l_mouse_mask.shape != (256, 256):
            l_green_frame_file = direc.file(exp_folder=EXP, fname="left green")
            l_green_frame = np.load(l_green_frame_file)

            plt.figure()
            plt.title('Left Mouse Left Hemisphere')
            plt.imshow(l_green_frame, cmap='gray', vmin=0, vmax=150)
            LM_left_hem = RoiPoly(color='b')
            plt.title('Left Mouse Right Hemisphere')
            plt.imshow(l_green_frame, cmap='gray', vmin=0, vmax=150)
            LM_right_hem = RoiPoly(color='r')

            plt.title('Left Mouse Hemispheres')
            plt.imshow(l_green_frame, cmap='gray', vmin=0, vmax=150)
            LM_left_hem.display_roi()
            LM_right_hem.display_roi()
            plt.xticks([])
            plt.yticks([])
            l_mouse_mask = np.logical_or(
                LM_left_hem.get_mask(l_mouse_frames[2000]),
                LM_right_hem.get_mask(l_mouse_frames[2000]))

        above_threshold = np.where(roi_gradient_signal >= threshold)[0]
        interaction_time = np.arange(start_interaction, end_interaction)
        solo_time = np.setdiff1d(
            np.arange(roi_gradient_signal.size),
            np.arange(start_first_translation, end_second_translation))
        solo_whisk_index = np.intersect1d(above_threshold, solo_time)
        social_whisk_index = np.intersect1d(above_threshold, interaction_time)
Example #7
0
import numpy as np  # noqa: E402
import pandas as pd  # noqa: E402
from pandas import DataFrame, Series  # noqa: E402

import pims  # noqa: E402
import trackpy as tp  # noqa: E402
from roipoly import RoiPoly  # noqa: E402

frames = pims.ImageSequence("../test/wt_pos1/mag1/*.tif", as_grey=True)

# print(frames[0])  # first frame

plt.imshow(frames[0])  # show the image
immobile_bead = RoiPoly(
    color='b')  # draw the ROI on shown image, shows fig by default

plt.imshow(frames[0])  # show image first
immobile_bead.display_roi()  # overlay ROI on shown image
plt.show()  # show the plot

mask = immobile_bead.get_mask(frames[0])  # call mask attribute from ROI object
print(mask)
plt.imshow(mask)
plt.show()

frame_zero = frames[0]

frame_zero[~mask] = 0
plt.imshow(frame_zero)
plt.show()