def test_analysis_mean_color(): img_pil = Image.open("data/original_images/lenna.png") img_cv = cv.imread("data/original_images/lenna.png") imanalysis = imagewizard.Analysis() res = imanalysis.mean_color(img_pil, 'rgb') res1 = imanalysis.mean_color(img_cv, 'bgr') print("PIL immage - mean color (RGB) :", res) print("CV immage - mean color (RGB) :", res1)
def test_dominant_color(): img_pil = Image.open("data/original_images/lenna.png") img_cv = cv.imread("data/original_images/lenna.png") imanalysis = imagewizard.Analysis() import time start = time.time() res = imanalysis.dominant_colors(img_pil, 3, 'rgb') end = time.time() res1 = imanalysis.dominant_colors(img_cv, 3, 'bgr') print("PIL immage - dominant color (RGB) :\n", res) print("CV immage - dominant color (RGB) :\n", res1) print("Time taken: ", end-start)
def trim_to_content(): # filename_in = "data/original_images/san_disk_white_pad.png" filename_in = "data/original_images/quiet_flow10.png" iw_analysis = imagewizard.Analysis() pil_im = Image.open(filename_in) pil_im = iw_analysis.trim_to_content(pil_im) or_im = cv.imread(filename_in) cv_im = iw_analysis.trim_to_content(or_im, 'bgr') # cv.imshow("original", or_im) # cv.imshow("trimmed cv image", cv_im) # pil_im.show() # cv.imshow("trimmed pil image", pil_im) cv.imwrite('crop_to_content_image.png', cv_im) cv.waitKey(0) cv.destroyAllWindows()
class TestAnalysis(unittest.TestCase): im_analysis = imagewizard.Analysis() lenna_org = cv.imread("data/original_images/lenna.png") quiet_flow_org = cv.imread("data/original_images/quiet_flow10.png") # mean color test mean_actual = (180, 99, 105) mean_test = im_analysis.mean_color(lenna_org, 'bgr') # mode color test mode_actual = (88, 18, 60) mode_test = im_analysis.frequent_color(lenna_org, 'bgr') # trim to content test trim_actual = cv.imread( "data/analysed_images/crop_to_content/trimmed_quite_flow10.png") trim_test = im_analysis.trim_to_content(quiet_flow_org, 'bgr') # dominant color test dominant_actual = np.asarray([[223, 163, 144], [108, 33, 71], [193, 95, 99]]) dominant_test = im_analysis.dominant_colors(lenna_org, 3, 'bgr') def test_mean(self): npt.assert_array_equal( self.mean_actual, self.mean_test, 'mean/average color does not equal actual result') def test_mode(self): npt.assert_array_equal( self.mode_actual, self.mode_test, 'mode/frequent color does not equal actual result') def test_trim(self): npt.assert_array_equal( self.trim_actual, self.trim_test, 'trimmed test image does not equal actual result') def test_dominant(self): npt.assert_array_equal(self.dominant_actual, self.dominant_test, 'dominant colors does not equal actual result')