def test_imsave(): fh, tempFilename = tempfile.mkstemp('.png') os.close(fh) try: for filename in all_test_images: filename = _locate_test_image(filename) a = qimage2ndarray.imread(filename) ok = qimage2ndarray.imsave(tempFilename, a) assert ok b = qimage2ndarray.imread(tempFilename) assert_equal(a.shape, b.shape) assert numpy.all(a == b) finally: os.unlink(tempFilename)
def loadAreasofInterest(self, image): self.unloadAreasOfInterest() img_arr = qimage2ndarray.imread(self.output_dir + image['name']) img_width = img_arr.shape[1] - 1 img_height = img_arr.shape[0] - 1 count = 0 cur_pos = 0 self.highlights = [] for area_of_interest in image['areas_of_interest']: center = area_of_interest['center'] radius = area_of_interest['radius'] + 10 crop_arr = self.crop_image(img_arr, center[0] - radius, center[1] - radius, center[0] + radius, center[1] + radius) highlight = QtImageViewer(self.scrollAreaWidgetContents, center, True) highlight.setObjectName("highlight" + str(count)) highlight.setMinimumSize(QSize(190, 190)) highlight.aspectRatioMode = Qt.KeepAspectRatio img = qimage2ndarray.array2qimage(crop_arr) highlight.setImage(img) highlight.canZoom = False highlight.canPan = False self.verticalLayout_2.addWidget(highlight) self.highlights.append(highlight) highlight.leftMouseButtonPressed.connect( self.area_of_interest_click) count += 1
def test_imread_gray_alpha(): filename = _locate_test_image('test_box_shadow.png') gray = qimage2ndarray.imread(filename) assert 200 < gray.max() <= 255 assert_equal(numpy.ndim(gray), 3) assert_equal(gray.shape, (50, 111, 2))
def test_imread_gray(): filename = _locate_test_image('test_gray.jpg') gray = qimage2ndarray.imread(filename) assert 200 < gray.max() <= 255 assert_equal(numpy.ndim(gray), 2) assert_equal(gray.shape, (11, 16))
def test_imread_rgba(): filename = _locate_test_image('test_colored_shadow.png') rgb = qimage2ndarray.imread(filename) assert_equal(rgb.min(), 0) assert_equal(rgb.max(), 255) assert_equal(numpy.ndim(rgb), 3) assert_equal(rgb.shape, (50, 111, 4))
def test_imread_box(): filename = _locate_test_image('test_box.png') gray = qimage2ndarray.imread(filename) assert_equal(gray.min(), 0) assert_equal(gray.max(), 255) assert_equal(numpy.ndim(gray), 2) assert_equal(gray.shape, (50, 111))
def test_imread_against_scipy_misc(): try: import scipy.misc except ImportError: raise SkipTest for filename in all_test_images: a = scipy.misc.imread(filename) b = qimage2ndarray.imread(filename) assert_equal(a.shape, b.shape) assert numpy.all(a == b)
def test_imread_against_scipy_ndimage(): try: import scipy.ndimage except ImportError: raise SkipTest for filename in all_test_images: a = scipy.ndimage.imread(filename) b = qimage2ndarray.imread(filename) assert_equal(a.shape, b.shape) assert numpy.all(a == b)
def open_photo(self, way): # way = QtWidgets.QFileDialog.getOpenFileName(self, 'Open photo', '')[0] if isinstance(way, tuple): way = way[0] if way: self.video = False image = cv2.cvtColor(qimage2ndarray.imread(way), cv2.COLOR_BGR2RGB) self.old_frame = cv2.resize( image, (self.video_size.width(), self.video_size.height()), interpolation=cv2.INTER_AREA) self.play_pause(1)
def test_imread_masked_no_alpha(): filename = _locate_test_image('test_gray.jpg') gray = qimage2ndarray.imread(filename, masked=True) assert 200 < gray.max() <= 255 assert_equal(numpy.ndim(gray), 2) assert_equal(gray.shape, (11, 16)) assert not numpy.ma.is_masked(gray)
def test_imread_masked_no_alpha(): filename = _locate_test_image('test_gray.jpg') gray = qimage2ndarray.imread(filename, masked = True) assert 200 < gray.max() <= 255 assert_equal(numpy.ndim(gray), 2) assert_equal(gray.shape, (11, 16)) assert not numpy.ma.is_masked(gray)
def test_imread_against_matplotlib(): try: import matplotlib.pyplot except ImportError: raise SkipTest for filename in all_test_images: a = matplotlib.pyplot.imread(filename) b = qimage2ndarray.imread(filename) assert_equal(a.shape, b.shape) if a.max() == 1.0: # strange MPL API: only the PNG has 0..1.0 range a *= 255 assert numpy.all(numpy.abs(a - b) < 1e-8)
def click_Subtract(self): print('SubtractButton click') fileNames = \ QFileDialog.getOpenFileNames(self, 'Open file', '', 'Images (*.bmp)', None, QFileDialog.DontUseNativeDialog)[0] QApplication.setOverrideCursor(QtCore.Qt.WaitCursor) if fileNames: try: for i in fileNames: self.images.insertRows(image(imread(i), i, sign='-')) except ValueError as e: QMessageBox.about(self, "Error", str(e)) self.buttons_enabled() QApplication.restoreOverrideCursor()
def test_imread_masked(): filename = _locate_test_image('test_box_shadow.png') gray = qimage2ndarray.imread(filename, masked=True) assert 200 < gray.max() <= 255 assert_equal(numpy.ndim(gray), 2) assert_equal(gray.shape, (50, 111)) assert numpy.ma.is_masked(gray) masked_count = gray.mask.sum() assert 0 < masked_count < numpy.product(gray.shape) assert_equal(masked_count, 1464)
def test_imread_masked(): filename = _locate_test_image('test_box_shadow.png') gray = qimage2ndarray.imread(filename, masked = True) assert 200 < gray.max() <= 255 assert_equal(numpy.ndim(gray), 2) assert_equal(gray.shape, (50, 111)) assert numpy.ma.is_masked(gray) masked_count = gray.mask.sum() assert 0 < masked_count < numpy.product(gray.shape) assert_equal(masked_count, 1464)
def test_imread_file_not_found(): filename = 'non_existing_image_file.png' qimage2ndarray.imread(filename)
def app_logo(self): return qimage2ndarray.imread(self.get_resource("assets/img/logo.png"))