예제 #1
0
def resize_img_and_roi(img_fpath, roi_, new_size=None, sqrt_area=400.0):
    printDBG('[segm] imread(%r) ' % img_fpath)
    full_img = io.imread(img_fpath)
    (full_h, full_w) = full_img.shape[:2]                 # Image Shape
    printDBG('[segm] full_img.shape=%r' % (full_img.shape,))
    (rw_, rh_) = roi_[2:]
    # Ensure that we know the new chip size
    if new_size is None:
        target_area = float(sqrt_area) ** 2

        def _resz(w, h):
            ht = np.sqrt(target_area * h / w)
            wt = w * ht / h
            return (int(round(wt)), int(round(ht)))
        new_size_ = _resz(rw_, rh_)
    else:
        new_size_ = new_size
    # Get Scale Factors
    fx = new_size_[0] / rw_
    fy = new_size_[1] / rh_
    printDBG('[segm] fx=%r fy=%r' % (fx, fy))
    dsize = (int(round(fx * full_w)), int(round(fy * full_h)))
    printDBG('[segm] dsize=%r' % (dsize,))
    # Resize the image
    img_resz = cv2.resize(full_img, dsize, interpolation=cv2.INTER_LANCZOS4)
    # Get new ROI in resized image
    roi_resz = np.array(np.round(roi_ * fx), dtype=np.int64)
    return img_resz, roi_resz
예제 #2
0
def resize_img_and_roi(img_fpath, roi_, new_size=None, sqrt_area=400.0):
    printDBG('[segm] imread(%r) ' % img_fpath)
    full_img = io.imread(img_fpath)
    (full_h, full_w) = full_img.shape[:2]  # Image Shape
    printDBG('[segm] full_img.shape=%r' % (full_img.shape, ))
    (rw_, rh_) = roi_[2:]
    # Ensure that we know the new chip size
    if new_size is None:
        target_area = float(sqrt_area)**2

        def _resz(w, h):
            ht = np.sqrt(target_area * h / w)
            wt = w * ht / h
            return (int(round(wt)), int(round(ht)))

        new_size_ = _resz(rw_, rh_)
    else:
        new_size_ = new_size
    # Get Scale Factors
    fx = new_size_[0] / rw_
    fy = new_size_[1] / rh_
    printDBG('[segm] fx=%r fy=%r' % (fx, fy))
    dsize = (int(round(fx * full_w)), int(round(fy * full_h)))
    printDBG('[segm] dsize=%r' % (dsize, ))
    # Resize the image
    img_resz = cv2.resize(full_img, dsize, interpolation=cv2.INTER_LANCZOS4)
    # Get new ROI in resized image
    roi_resz = np.array(np.round(roi_ * fx), dtype=np.int64)
    return img_resz, roi_resz
예제 #3
0
def extract_chip(img_fpath, roi, theta, new_size):
    'Crops chip from image ; Rotates and scales; Converts to grayscale'
    # Read parent image
    #printDBG('[cc2] reading image')
    imgBGR = io.imread(img_fpath)
    #printDBG('[cc2] building transform')
    # Build transformation
    (rx, ry, rw, rh) = roi
    (rw_, rh_) = new_size
    Aff = build_transform(rx, ry, rw, rh, rw_, rh_, theta)
    #printDBG('[cc2] rotate and scale')
    # Rotate and scale
    imgBGR = cv2.warpAffine(imgBGR, Aff, (rw_, rh_), **cv2_warp_kwargs)
    #printDBG('[cc2] return extracted')
    return imgBGR
예제 #4
0
def extract_chip(img_fpath, roi, theta, new_size):
    'Crops chip from image ; Rotates and scales; Converts to grayscale'
    # Read parent image
    #printDBG('[cc2] reading image')
    imgBGR = io.imread(img_fpath)
    #printDBG('[cc2] building transform')
    # Build transformation
    (rx, ry, rw, rh) = roi
    (rw_, rh_) = new_size
    Aff = build_transform(rx, ry, rw, rh, rw_, rh_, theta)
    #printDBG('[cc2] rotate and scale')
    # Rotate and scale
    imgBGR = cv2.warpAffine(imgBGR, Aff, (rw_, rh_), **cv2_warp_kwargs)
    #printDBG('[cc2] return extracted')
    return imgBGR
예제 #5
0
def mask_creator_demo(mode=0):
    print('*** START DEMO ***')
    print('mode = %r' % mode)
    try:
        from hscom import fileio as io
        img = io.imread('/lena.png', 'RGB')
    except ImportError as ex:
        print('cant read lena: %r' % ex)
        img = np.random.uniform(255, 255, size=(100, 100))

    ax = plt.subplot(111)
    ax.imshow(img)

    if mode == 0:
        mc = MaskCreator(ax)
        # Do interaction
        plt.show()
        # Make mask from selection
        mask = mc.get_mask(img.shape)
        # User must close previous figure
    elif mode == 1:
        from hsgui import guitools
        from hsviz import draw_func2 as df2
        ax.set_title('Click two points to select an ROI (old mode)')
        # Do selection
        roi = guitools.select_roi()
        # Make mask from selection
        mask = roi_to_mask(img.shape, roi)
        # Close previous figure
        df2.close_all_figures()

    # Modify the image with the mask
    masked_img = apply_mask(img, mask)
    # show the modified image
    plt.imshow(masked_img)
    plt.title('Region outside of mask is darkened')
    print('show2')
    plt.show()
예제 #6
0
파일: viz.py 프로젝트: obaiga/hotspotter
def show_splash(fnum=1, **kwargs):
    #printDBG('[viz] show_splash()')
    splash_fpath = io.splash_img_fpath()
    img = io.imread(splash_fpath)
    df2.imshow(img, fnum=fnum, **kwargs)
예제 #7
0
from PyQt4.Qt import (QAbstractItemModel, QModelIndex, QVariant, QWidget,
                      Qt, QObject, pyqtSlot, QKeyEvent)
# HotSpotter
from hotspotter import DataStructures as ds
from hotspotter import HotSpotterAPI
from hotspotter import HotSpotterAPI as api
from hotspotter import algos
from hotspotter import chip_compute2 as cc2
from hotspotter import feature_compute2 as fc2
from hotspotter import load_data2 as ld2
from hotspotter import match_chips3 as mc3
from hotspotter import matching_functions as mf
from hotspotter import segmentation
from hotspotter import voting_rules2 as vr2
from hotspotter import nn_filters
from hscom import Parallelize as parallel
from hscom import fileio as io
from hscom import helpers as helpers
from hsviz import draw_func2 as df2
from hsviz import extract_patch
from hsviz import viz
import dev

if __name__ == 'main':
    multiprocessing.freeze_support()
    #exec(open('dbgimport.py').read())
    if '--img' in sys.argv:
        img_fpath_ = helpers.dbg_get_imgfpath()
        np_img_ = io.imread(img_fpath_)
        img_ = Image.open(img_fpath_)
예제 #8
0
파일: viz.py 프로젝트: Erotemic/hotspotter
def show_splash(fnum=1, **kwargs):
    #printDBG('[viz] show_splash()')
    splash_fpath = io.splash_img_fpath()
    img = io.imread(splash_fpath)
    df2.imshow(img, fnum=fnum, **kwargs)
예제 #9
0
 def gx2_image(hs, gx):
     img_fpath = hs.gx2_gname(gx, full=True)
     img = io.imread(img_fpath)
     return img
예제 #10
0
 def _read_chip(hs, fpath):
     return io.imread(fpath)
예제 #11
0
 def gx2_image(hs, gx):
     img_fpath = hs.gx2_gname(gx, full=True)
     img = io.imread(img_fpath)
     return img
예제 #12
0
 def _read_chip(hs, fpath):
     return io.imread(fpath)