From 9acd709fb9b39641474515b10971c03a2f48009b Mon Sep 17 00:00:00 2001 From: Edinei Cavalcanti Date: Thu, 20 Feb 2020 12:20:51 -0300 Subject: [PATCH 1/2] Add initialy Remove Similar --- assets/app.js | 33 ++++++++++++++++++++++++++++++--- index.html | 7 +++++-- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/assets/app.js b/assets/app.js index 889bd81..d858305 100644 --- a/assets/app.js +++ b/assets/app.js @@ -21,9 +21,18 @@ function RunOnLoad() { let mapOfPopulariesResult = mapOfPopularies(imgData); let mostPopularRank = []; + var isChecked = document.getElementById('removeSimilar').checked; + let rankTotal = 5; for (let index = 0; index < rankTotal; index++) { - let theMostPopular = getTheMostPopular(mapOfPopulariesResult); + let theMostPopular; + if (isChecked) { + theMostPopular = getTheMostPopular(mapOfPopulariesResult, mostPopularRank); + } + else { + theMostPopular = getTheMostPopular(mapOfPopulariesResult); + } + mostPopularRank.push(theMostPopular); mapOfPopulariesResult.delete(theMostPopular[0]); } @@ -39,14 +48,32 @@ function RunOnLoad() { }; reader.readAsDataURL(e.target.files[0]); - function getTheMostPopular(mapOfPopulariesResult) { + function getTheMostPopular(mapOfPopulariesResult, filterSimilarPixel) { let mostPopular = [...mapOfPopulariesResult.entries()].reduce((a, e) => - e[1] > a[1] ? e : a + (e[1] > a[1]) && IsSimilarPixel(a[0], filterSimilarPixel) ? e : a ); return mostPopular; } + function IsSimilarPixel(pixelToCompareRgb, pixels) { + if (!pixels) { + return true; + } + //12, 105, 196 + pixelToCompareRgb = pixelToCompareRgb.split(", "); + for (const pixel of pixels) { + for (const pixelToCompare of pixelToCompareRgb) { + let constains = pixel.includes(pixelToCompare); + if (constains) { + return false; + } + } + } + + return true; + } + function setBackgroundColor(elementId, colorRGB) { var element = document.getElementById(elementId); element.style.backgroundColor = `rgb(${colorRGB})`; diff --git a/index.html b/index.html index db2d403..b265af8 100644 --- a/index.html +++ b/index.html @@ -4,13 +4,16 @@ - Mostpopularpx: The Most popular pixels in an image (Draft) + (Draft) Mostpopularpx: The Most popular pixels in an image +

(Draft) Mostpopularpx: The Most popular pixels in an image


- +
+
+
From d6135bfaa91d3f7de71d6e96b2333771c6d5b47d Mon Sep 17 00:00:00 2001 From: Edinei Cavalcanti Date: Thu, 20 Feb 2020 13:35:23 -0300 Subject: [PATCH 2/2] Ajusts IsSimilarPixel --- assets/app.js | 13 ++++++------- index.html | 5 +++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/assets/app.js b/assets/app.js index d858305..5302e8d 100644 --- a/assets/app.js +++ b/assets/app.js @@ -6,7 +6,6 @@ function RunOnLoad() { var ctx = canvas.getContext("2d"); function handleImage(e) { - console.log("handleImage"); var reader = new FileReader(); reader.onload = function(event) { var img = new Image(); @@ -16,7 +15,7 @@ function RunOnLoad() { ctx.drawImage(img, 0, 0, canvas.width, canvas.height); var imgData = ctx.getImageData(0, 0, canvas.width, canvas.height); - //invertColors(ctx, imgData) + //invertColors(ctx, imgData); let mapOfPopulariesResult = mapOfPopularies(imgData); let mostPopularRank = []; @@ -60,18 +59,18 @@ function RunOnLoad() { if (!pixels) { return true; } - //12, 105, 196 + pixelToCompareRgb = pixelToCompareRgb.split(", "); for (const pixel of pixels) { for (const pixelToCompare of pixelToCompareRgb) { - let constains = pixel.includes(pixelToCompare); - if (constains) { - return false; + let constains = pixel[0].split(", ").filter(value => pixelToCompare == value); + if (constains.length > 0) { + return true; } } } - return true; + return false; } function setBackgroundColor(elementId, colorRGB) { diff --git a/index.html b/index.html index b265af8..aed0646 100644 --- a/index.html +++ b/index.html @@ -10,10 +10,11 @@

(Draft) Mostpopularpx: The Most popular pixels in an image

-
-


+
+
+