How to determine average (R,G,B) values in a image ?

228 views
Skip to first unread message

Hussain

unread,
Aug 25, 2016, 10:12:15 AM8/25/16
to MIT App Inventor Forum

 I want to find the average (R,G,B) components over an area of an image say 100 pixel x 100 pixel but I have not find any canvas block to to that. Please give me any suggestion how to do that in app inventor?

ScottFerguson

unread,
Aug 25, 2016, 11:31:36 AM8/25/16
to MIT App Inventor Forum
You can use this method to find the RGB value of a pixel.

One method that might work (but likely too slowly to be useful) is to store the value returned by GetBackgroundPixelColor in a list for each pixel.
Total the values in the list then average that total.
The averaged value might be the average MITAI color value.
You could then convert the result to an RGB value.

A faster method might be to use the WebViewer component and javascript code to determine the average RGB value and return that value as a list to MITAI proper using the WebViewer WebViewString property.
Google: javascript average RGB value

Taifun

unread,
Aug 25, 2016, 11:39:26 AM8/25/16
to MIT App Inventor Forum
see also this snippet (which follows Scott's first method) you could convert into App Inventor http://stackoverflow.com/a/20785902/1545993 

alternatively if you like to have a fast method, then you could consider to write your own extension and create a block yourself...

more information about how to create an extension see here https://groups.google.com/d/msg/mitappinventortest/Ip2AX036d0U/5NJlAEbFCgAJ
however that will be more advanced and will require some Java skills...

Taifun

Trying to push the limits of App Inventor! Snippets, Tutorials and Extensions from Pura Vida Apps by Taifun. 



Hussain

unread,
Aug 25, 2016, 2:47:35 PM8/25/16
to mitappinv...@googlegroups.com
After all the google searches what I have understand is that I have to load the image into a html/JavaScript as a csv file and create a button in the JavaScript so that when I click the button it will run the code in the script and find the desired average(r,g,b) value within the html/javascript. 

Sir, I have just started app inventor for building apps therefore I find it difficult to use WebViewString property to find the (R,G,B) components from a javascript...can you please give me some idea how can I create the javascript and how to use the WebViewString property.
 
Reply all
Reply to author
Forward
0 new messages