# Path: reid/preproc/imageproc.py
# def imtranslate(image, translation):
# def imresize(image, shape, keep_ratio=False):
# def subtract_luminance(rgbimg, mean_luminance=None):
# def scale_per_channel(img, scale_range):
# def binarize(img, threshold):
# def images2mat(images):
# 
# Path: reid/utils/gui_utils.py
# def ndarray2qimage(array):
#     """Convert from numpy.ndarray to QImage
# 
#     Args:
#         array: An numpy.ndarray of size h*w*c. The number of channels could be
#                either one or three, one stands for grayscale image, three stands
#                for RGB image. The dtype must be numpy.uint32.
# 
#     Returns:
#         A QImage object constructed from given array.
#     """
# 
#     array = array.astype('uint32')
# 
#     if array.ndim == 2:
#         h, w = array.shape
#         data = (255 << 24 | array << 16 | array << 8 | array)
#     elif array.ndim == 3:
#         h, w, c = array.shape
#         if c == 1:
#             data = (255 << 24 | array[:,:,0] << 16 | array[:,:,0] << 8 | array[:,:,0])
#         elif c == 3:
#             data = (255 << 24 | array[:,:,0] << 16 | array[:,:,1] << 8 | array[:,:,2])
#         else:
#             raise ValueError("ndarray2qimage cannot recognize the image type")
#     else:
#         raise ValueError("ndarray2qimage cannot recognize the image type")
# 
#     data = data.ravel()
#     return QImage(data, w, h, QImage.Format_RGB32).copy()


import sys
import os
import shelve
import numpy
import attrconf
from scipy.io import loadmat, savemat
from PySide import QtGui, QtCore
from reid.preproc import imageproc
from reid.utils.gui_utils import ndarray2qimage

        # Record to selected images
        ind = numpy.where(mask == 1)
        for item in self._gallery.selectedItems():
            v, k = map(int, item.text().split(','))
            self.mat_attributes[self.cur_pid, v][0, k][ind] = attr[ind]

    def hint_for_conflict(self):
        def setbg(gbox, color):
            gbox.setStyleSheet('background-color: {0}'.format(color))

        for i, gbox in enumerate(self._unival_gboxes):
            setbg(gbox, '#FF4136' if self._uconf[i] else 'white')

        for i, gbox in enumerate(self._multival_gboxes):
            setbg(gbox, '#FF4136' if self._mconf[i] else 'white')

    def show_pid(self, pid):
        # Show images
        self._gallery.itemSelectionChanged.disconnect(self.update_attr)
        self._gallery.clear()

        for v in xrange(self.mat_images.shape[1]):
            if self.mat_images[pid, v].size == 0: break
            for k in xrange(self.mat_images[pid, v].shape[1]):
                img = self.mat_images[pid, v][0, k]
                img = ndarray2qimage(imageproc.imresize(img, (256, 96)))
                item = QtGui.QListWidgetItem(
                    QtGui.QIcon(QtGui.QPixmap.fromImage(img)),
                    '{0},{1}'.format(v, k))

# Path: reid/preproc/imageproc.py
# def imtranslate(image, translation):
# def imresize(image, shape, keep_ratio=False):
# def subtract_luminance(rgbimg, mean_luminance=None):
# def scale_per_channel(img, scale_range):
# def binarize(img, threshold):
# def images2mat(images):
# 
# Path: reid/utils/gui_utils.py
# def ndarray2qimage(array):
#     """Convert from numpy.ndarray to QImage
# 
#     Args:
#         array: An numpy.ndarray of size h*w*c. The number of channels could be
#                either one or three, one stands for grayscale image, three stands
#                for RGB image. The dtype must be numpy.uint32.
# 
#     Returns:
#         A QImage object constructed from given array.
#     """
# 
#     array = array.astype('uint32')
# 
#     if array.ndim == 2:
#         h, w = array.shape
#         data = (255 << 24 | array << 16 | array << 8 | array)
#     elif array.ndim == 3:
#         h, w, c = array.shape
#         if c == 1:
#             data = (255 << 24 | array[:,:,0] << 16 | array[:,:,0] << 8 | array[:,:,0])
#         elif c == 3:
#             data = (255 << 24 | array[:,:,0] << 16 | array[:,:,1] << 8 | array[:,:,2])
#         else:
#             raise ValueError("ndarray2qimage cannot recognize the image type")
#     else:
#         raise ValueError("ndarray2qimage cannot recognize the image type")
# 
#     data = data.ravel()
#     return QImage(data, w, h, QImage.Format_RGB32).copy()


# Path: scripts/labelattr.py
import sys
import os
import shelve
import numpy
import attrconf
from scipy.io import loadmat, savemat
from PySide import QtGui, QtCore
from reid.preproc import imageproc
from reid.utils.gui_utils import ndarray2qimage


        # Record to selected images
        ind = numpy.where(mask == 1)
        for item in self._gallery.selectedItems():
            v, k = map(int, item.text().split(','))
            self.mat_attributes[self.cur_pid, v][0, k][ind] = attr[ind]

    def hint_for_conflict(self):
        def setbg(gbox, color):
            gbox.setStyleSheet('background-color: {0}'.format(color))

        for i, gbox in enumerate(self._unival_gboxes):
            setbg(gbox, '#FF4136' if self._uconf[i] else 'white')

        for i, gbox in enumerate(self._multival_gboxes):
            setbg(gbox, '#FF4136' if self._mconf[i] else 'white')

    def show_pid(self, pid):
        # Show images
        self._gallery.itemSelectionChanged.disconnect(self.update_attr)
        self._gallery.clear()

        for v in xrange(self.mat_images.shape[1]):
            if self.mat_images[pid, v].size == 0: break
            for k in xrange(self.mat_images[pid, v].shape[1]):
                img = self.mat_images[pid, v][0, k]
                img = ndarray2qimage(imageproc.imresize(img, (256, 96)))
                item = QtGui.QListWidgetItem(
                    QtGui.QIcon(QtGui.QPixmap.fromImage(img)),
                    '{0},{1}'.format(v, k))

                self._gallery.addItem(item)