PDA

View Full Version : look for continuous group in array


Laviva
01-19-2008, 01:11 AM
Hi!
Im just a beginer and I cant one week long make to work second part of this script : it should search for group of pixels (the group have count of pixels called rozloha).The pixels have to have the same or the best posible aproximation between inserted picture and inserted value of r, g, b. But the pixels in this array have to form continuous group, I want them to have common edge one to another. In the first step returns array of boxes and I search for the group using the height of created boxes..but I cant find how to write the syntax for finding the group of pixels..this is way im searching.. Im near, comletely wrong :wip: ? any idea?
thanks!

Ladi

Laviva
01-19-2008, 07:46 AM
here is the script:

work_bmp = openbitmap "D:\parametric urbanism\sml.tga"

bmp_w = work_bmp.width
bmp_h = work_bmp.height


koord_pixelu = #()
jedna_plocha = #()
e_jedna_plocha = #()
nej_score = 1000
nej_size_value = 0 as float
nej_id = 0 as integer
id_pixelu = 0 as integer
rozloha = 20

rollout ScriptTool "vstupní hodnoty RGB"

(

spinner hodnota_r "R:" type:#integer range:[1,255,100]
spinner hodnota_g "G:" type:#integer range:[1,255,100]
spinner hodnota_b "B:" type:#integer range:[1,255,100]

button create "start procesu"

on create pressed do
(
progressstart "Generating Objects..."
for h = 1 to bmp_h do
(
progressupdate (h as float /bmp_h *100)
--update the progress indicator

pixel_line = getpixels work_bmp [0,(h-1)] bmp_w
progressupdate (h as float /bmp_h *100)

for w = 1 to bmp_w do
(
--print bmp_w
id_pixelu += 1
x = w as integer
y = h as integer
r = pixel_line[w].r as integer
g = pixel_line[w].g as integer
b = pixel_line[w].b as integer
score = ( (abs (r - hodnota_r.value)) + (abs (b - hodnota_b.value)) + (abs (g - hodnota_g.value) ))

size_value = ( 1000000 / ((score+1)^2) )
if r != 255 and g != 255 and b !=255 do

(append koord_pixelu #(#(id_pixelu),#(x),#(y),#(size_value))



new_object = convertToPoly (box length:100 width:100 height:size_value)


new_object.pos = [x*100, (-y*100), 0]


new_material = standardmaterial diffuse:[(255-score),0,0]

new_object.material = new_material
)

if score < nej_score do
(
nej_score = score
nej_id = id_pixelu
nej_size_value = size_value
)

)--end w loop
)

print koord_pixelu.count




i = nej_size_value
jedna_plocha = #()
while (i>=0) do
(
print i
obj = $box* as array
vyhovujici_boxy = #()
vyhovujici_boxy2 = #()
for j in obj do
(
if j.max.z >= i then
(
appendIfUnique vyhovujici_boxy j
appendIfUnique vyhovujici_boxy2 j
)
if vyhovujici_boxy.count >= rozloha do
(
jedna_plocha = #()

start = 1
for v=1 to vyhovujici_boxy2.count do
(for u=1 to vyhovujici_boxy2.count do
(if (distance vyhovujici_boxy2[v] vyhovujici_boxy2[u]) == 100 do
(if start == 1 do
(appendIfUnique jedna_plocha vyhovujici_boxy2[v]
appendIfUnique jedna_plocha vyhovujici_boxy2[u]
deleteItem vyhovujici_boxy2 u
deleteItem vyhovujici_boxy2 v
start=0
)

for k in jedna_plocha do
(

(for l =1 to vyhovujici_boxy2.count do --beru prvky od prvniho podle jejich id, u tvojeho zapisu jsme nevedeli, jake id ma
(
if (distance vyhovujici_boxy2[l] k) == 100 do
(
appendIfUnique jedna_plocha vyhovujici_boxy2[l]
deleteItem vyhovujici_boxy2 l



for s =1 to jedna_plocha.count do
(
prvky = #()
e_jedna_plocha = #(#(s,prvky))

for d in jedna_plocha do
(
if distance jedna_plocha[s] d == 100 do
( appendIfUnique prvky d
if e_jedna_plocha.count >= rozloha then exit
)
)
print e_jedna_plocha.count

if e_jedna_plocha.count >= rozloha then exit
)
if e_jedna_plocha.count >= rozloha then exit

)
if e_jedna_plocha.count >= rozloha then exit
)
)
if e_jedna_plocha.count >= rozloha then exit

)
if e_jedna_plocha.count >= rozloha then exit

)

if e_jedna_plocha.count >= rozloha then exit

)
if e_jedna_plocha.count >= rozloha then exit
)
print jedna_plocha.count
for h in jedna_plocha do
(
new_material = standardmaterial diffuse:[255,255,255]
h.material = new_material
)
for m in e_jedna_plocha do
(
new_material = standardmaterial diffuse:[255,0,0]
h.material = new_material
)

if e_jedna_plocha.count >= rozloha then exit
)
print vyhovujici_boxy.count
print jedna_plocha.count
print e_jedna_plocha

i = i-10
)

progressend ()

CGTalk Moderation
01-19-2008, 07:46 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.