After taking an extremely long break I need some help with a filter I want to make. The existing cubism one can only handle predetermined shapes layered on top of each other and doesn’t really look all that cubist, so I thought I’d make one that uses segmentation to cut up and reorganise the image. So far it looks like this:
#@gui Cubism: fx_jr_cubism_preview
#@gui : sep = separator()
#@gui : 0. Recompute = button()
#@gui : 1. Threshold=float(2,0,15)
#@gui : 2. Smoothness=float(1,0,500)
#@gui : 3. Amplitude=float(10,0,100)
fx_jr_cubism:
+to_rgb b. $2 segment_watershed. $1 # add energy polygonize option
f. ">begin(rand=u(100,200));srand(i*rand);u"
sh. 0 n. 0,1 rm.
sh. 1 n. 0,1 rm.
sh. 2 n. 0,{2*pi} rm.
amp={$3*w*0.01}
f.. "val=(I(#1));
xoff=val[0]*"$amp";
yoff=val[1]*"$amp";
ang=val[2];
I(x*cos(ang)+y*sin(ang)+val[0],y*cos(ang)-x*sin(ang)+val[1],0,3,3)"
rm.
fx_jr_cubism_preview:
fx_jr_cubism ${2-4}
It takes segmented copies of images and uses the copies to generate maps with the same segment shapes but pseudorandomised values. (Thank goodness for srand()
!) The maps are used not only to offset parts of the original image but also to rotate them by any angle. If I add a bit of code I can get more control over the angle.
Now I have two problems:
-
anti-aliasing. Like with the kaleidoscope layer cake, I don’t want to take the brutal route and temporarily upscale the image.
-
rotating from the centre of each segment. How would I find the centre of each segment and verify that a pixel belongs to a certain segment?
Combining the two problems makes this even more difficult since I would need to slightly blur the boundaries between the segments, which would make the second problem harder.
I wanted to avoid repurposing the patchmatch resynthesise thing which already has a blending size parameter which can be used for anti-aliasing purposes, but the second problem would still exist and I don’t know how I’d rotate the image within each patch.
Edit: so my first idea is to scan for patches of the map which have different values. I’ll use a fourth channel for the map to filter out which patches have already been scanned
Edit 2: is there anything which will dump the x and y coordinates of all pixels with a certain value? Also how does rot()
work if there’s no difference between 1D and 2D vectors?