[partially solved] Way to get average Pixelvalue of a picture segment defined by geometric object/path?

Discuss SVG code, accessible via the XML Editor.
aik
Posts: 5
Joined: Wed Sep 02, 2015 1:10 am

[partially solved] Way to get average Pixelvalue of a picture segment defined by geometric object/path?

Postby aik » Sat Feb 13, 2016 9:22 pm

Is there a (simple) way to get the average value for pixels 'behind' geometric objects? I whant to do some mosaiic-style path and determine colors for each tile based on a raster/pixel image.

clarification image
Image

I'd like to have some getAvgValue(Path1) functionality… or SVG-mosaiic-filter or anything with that functionality
Last edited by aik on Thu Jul 07, 2016 9:22 pm, edited 1 time in total.

Lazur
Posts: 4344
Joined: Tue Jun 14, 2016 10:38 am

Re: Way to get average Pixelvalue of a picture segment defined by geometric object/path?

Postby Lazur » Sat Feb 13, 2016 9:50 pm

As far as I know the tiled clones are the closest at the moment.

Well you can use trace bitmap to sort out the image to separate colours.

Moini
Posts: 2053
Joined: Mon Oct 05, 2015 10:44 am

Re: Way to get average Pixelvalue of a picture segment defined by geometric object/path?

Postby Moini » Sun Feb 14, 2016 12:33 am

The dropper tool can average over circle-shaped areas (just click and drag). In many cases, that may suffice in terms of precision.
Something doesn't work? - Keeping an eye on the status bar can save you a lot of time!

Inkscape FAQ - Learning Resources - Website with tutorials (German and English)

aik
Posts: 5
Joined: Wed Sep 02, 2015 1:10 am

Re: Way to get average Pixelvalue of a picture segment defined by geometric object/path?

Postby aik » Thu Jul 07, 2016 9:20 pm

Thanks for answers =)

Unfortunatly your proposed solutions were not precise enough or can not be done automaticly via script.

I found a solution though it is not very fast - javascript based - so slow firefox crashes before finishing, but chromium does it.

Outline of what I did:

- have Image with pixeldata as canvas object

Code: Select all

for each pixel on canvas
   for each object
        check if object is containing pixel(x,y)
        store pixel value in array object->pixelvalue
   rof
rof
calculate mean color for each object in array

v1nce
Posts: 640
Joined: Wed Jan 13, 2010 4:36 am

Re: [partially solved] Way to get average Pixelvalue of a picture segment defined by geometric object/path?

Postby v1nce » Fri Jul 08, 2016 9:12 pm

Maybe you can skip the comparison with all your shapes.
create white image the same size of original
draw all your shapes onto this new image with ascending colors (make sure you're NOT using antialiasing)

iterate all pixels in the new image.
read the color of the pixel in the new image => this is the index [i] of your shape
(test if white it doesn't belong to any of your shapes)
read the color at same coordinates in the original =>push it to the array of pixel colors for shape i

for each shape compute mean of found pixels


Code: Select all

cache = new image(width,height)
cache.Fill(#fff)
For i = 0 to shapes.length
 shapes[i].fill(i)


For each pixel in cache
 Number of shape = cache.getImageData(pixel.x,pixel.y...)
  Shapepixels[number of shape]+=image.getImageData(pixel.x,pixel.y...)

For each shapepixels
 Compute mean
 

v1nce
Posts: 640
Joined: Wed Jan 13, 2010 4:36 am

Re: [partially solved] Way to get average Pixelvalue of a picture segment defined by geometric object/path?

Postby v1nce » Fri Jul 08, 2016 10:28 pm

there's place for some optimization on your code
exit as soon as you find the object
pixel x+1,y probably belongs to the same object than pixel x,y => check this object first

Code: Select all

lastobject = object;
for each pixel on canvas
   if lastobject contains(x,y)
     ...
   else
     for each object!=lastobject
          check if object is containing pixel(x,y)
            store pixel value in array object->pixelvalue
            lastobject = object
            exit for
     rof
rof
calculate mean color for each object in array


Return to “SVG / XML Code”

Who is online

Users browsing this forum: No registered users and 1 guest