Hmm, in that case this seems less about cut and more about the inputs to it. You can do cut on a vector, or individual parts so that’s already possible (you could even use min() and max() to do the same thing).
Is that x vector definitely right? Your input x positions are not even in order? Logically doable, but still… a bit on the messy side.
Then I have a idea. I would have two variable with size s where s is spectrum. And then use crop to extract 3*3 window per channel and find min/max per channel via for loop and insert it to the two variable. Then use cut(I,min_v,max_v). I think I will figure out how to avoid for loop though that’s not easy.
One other thing: if you’re using bicubic interp you can expect values outside the input range (overshoot), so you might have less precision loss using linear.
Ok, I did tried this.
outx=ax*ww+(ax*ay);
outy=ay*hh;
int_outx=int(outx);
int_outy=int(outy);
min_v=min(
I(#0,int_outx-1,int_outy-1,z,0,1),I(#0,int_outx,int_outy-1,z,0,1),I(#0,int_outx+1,int_outy-1,z,0,1),
I(#0,int_outx-1,int_outy,z,0,1),I(#0,int_outx,int_outy,z,0,1),I(#0,int_outx+1,int_outy,z,0,1),
I(#0,int_outx-1,int_outy+1,z,0,1),I(#0,int_outx,int_outy+1,z,0,1),I(#0,int_outx+1,int_outy+1,z,0,1)
);
max_v=max(
I(#0,int_outx-1,int_outy-1,z,0,1),I(#0,int_outx,int_outy-1,z,0,1),I(#0,int_outx+1,int_outy-1,z,0,1),
I(#0,int_outx-1,int_outy,z,0,1),I(#0,int_outx,int_outy,z,0,1),I(#0,int_outx+1,int_outy,z,0,1),
I(#0,int_outx-1,int_outy+1,z,0,1),I(#0,int_outx,int_outy+1,z,0,1),I(#0,int_outx+1,int_outy+1,z,0,1)
);
cut(I(#0,ax*ww+(ax*ay),ay*hh,z,2,1),min_v,max_v);
The end result of some image pixels are all the same where they’re not supposed to be. Other than that, almost no red channel are different which means I’m in the correct direction.
The min_v and max_v all should have different values per channels. vargmax/vargmin gives the wrong values.
EDIT: I used i instead of I. That works though I think it would be faster if it were possible with I instead. After doing this, the difference analysis image shows nearly completely black image where differences are found within corners.
I think I got it now. The difference should be definitely minimal now.
Just checking: are these behaving properly? There was an issue with argmax or argmin that I reported and was fixed a while back.
C:\Windows\System32>gmic echo {argmin([3,2,1],[5,-1,2],[1,3,-1])}
[gmic]-0./ Start G'MIC interpreter.
[gmic]-0./ 4
[gmic]-0./ End G'MIC interpreter.
C:\Windows\System32>gmic echo {vargmax([3,2,1],[5,-1,2],[1,3,-1])}
[gmic]-0./ Start G'MIC interpreter.
[gmic]-0./ 1,2,1
[gmic]-0./ End G'MIC interpreter.
It is. I don’t quite know why but the idea is
% include minimum and maximum values of luminance to the bin edges, to
% ensure that all luminance values are in one of the bins.
I.e. the first and last value is inherited from an image 2 steps ago, which results in a new first element that could be potentially larger than the second, and an overwritten last element. Why insert an element at the beginning and overwrite the last element and not do one or the other for both ends is another mystery.
Is this part of replicating the octave histogram thing? If so, there should be easier ways to get an output of x positions, especially if the “bins” are regular spaced (as they would be with a scalar second argument). I’ll think more about it!
My objective is to understand and replicate the functions. The algorithm itself is bad but I will PM the m-file.
I want to clean up csswap. My goal is to store all the commands in a vector variable, pick the right one and then execute it. I’ll see what I can do.
Edit: I have no idea how to do this.
I want a list of all the commands as if they’re in a vector like this: ['lch8','hsv',...]. This should be either appended to rgb2 or have 2rgb appended to it, and then executed. The substitution rules are far too confusing for me to understand how to do this.
A bonus thing I want to implement is text: csswap hsv,oklab8 should be a thing if possible.
Two things:
You can append strings with a period and equal.
str=a
str2=b
str.=$str2
str.=c
#str=abc#
Read the example below:
convert_colors_fwd=${arg\ 1+$5,rgb2hsi,rgb2hsl,rgb2hsv,rgb2hcy}
convert_colors_bwd=${arg\ 1+$5,hsi2rgb,hsl2rgb,hsv2rgb,hcy2rgb}
I thought that changed the variable’s name and not its value. Thanks for clearing that up, that’s a massive help.
Anyway, I found out that this works, so I could use it in future…
m "sc: comm=srgb u $comm{/2rgb}"
${"-sc"}
m "cs: comm=srgb u {/rgb2}$comm"
${"-cs"}
Edit: I haven’t figured out how to manipulate strings within the mathematical parser, but I’ve found something useful:
scfrom=Srgb
strlowercase $scfrom
scfrom=${}
csto=srgb
strlowercase $csto
scfrom=${}
m "sc: comm="$scfrom" u $comm{/2rgb}"
${"-sc"}
m "cs: comm="$csto" u {/rgb2}$comm"
${"-cs"}
Got it.
#@gui Colour Space Swap: csswap, csswap_preview()
#@gui : To RGB From = choice("RGB","sRGB","CMY","RYB","Ohta8","Ohta","YES8","YES","Kodak1-8","Kodak1","Lab8","Lab","Oklab","LUV","Jzazbz","YIQ8","YIQ","YUV8","YUV","YCbCr","YCbCrGLIC","YCbCrJPEG","YDbDr","XYZ8","XYZ","HSV8","HSV","HSL8","HSL","HSI8","HSI","LCH8","LCH","JzCzHz","HCY")
#@gui : From RGB To = choice("RGB","sRGB","CMY","RYB","Ohta8","Ohta","YES8","YES","Kodak1-8","Kodak1","Lab8","Lab","Oklab","LUV","Jzazbz","YIQ8","YIQ","YUV8","YUV","YCbCr","YCbCrGLIC","YCbCrJPEG","YDbDr","XYZ8","XYZ","HSV8","HSV","HSL8","HSL","HSI8","HSI","LCH8","LCH","Jzczhz","HCY")
#@gui : sep = separator(), Preview type = choice("Full","Forward horizontal","Forward vertical","Backward horizontal","Backward vertical","Duplicate top","Duplicate left","Duplicate bottom","Duplicate right","Duplicate horizontal","Duplicate vertical","Checkered","Checkered inverse"), Preview Split = point(50,50,0,0,200,200,200,0,10)
csswap:
scfrom=$1
csto=$2
if {('$scfrom'!='$csto')}
list=srgb,cmy,ryb,ohta8,ohta,yes8,yes,k18,k1,lab8,lab,oklab,luv,jzazbz,yiq8,yiq,yuv8,yuv,ycbcr,ycbcrglic,ycbcrjpeg,ydbdr,xyz8,xyz,hsv8,hsv,hsl8,hsl,hsi8,hsi,lch8,lch,jzczhz,hcy
repeat $! l[$>] split_opacity l[0] to_rgb
if {('$scfrom'!='rgb')&&('$scfrom'!='0')}
if {isnum($scfrom)}
scfrom=${arg\ $scfrom,$list}
else
strlowercase $scfrom
scfrom=${}
fi
m "sc: comm="$scfrom" u $comm{/2rgb}"
${"-sc"}
um sc
fi
if {('$csto'!='rgb')&&('$csto'!='0')}
if {isnum($csto)}
csto=${arg\ $csto,$list}
else
strlowercase $csto
csto=${}
fi
m "cs: comm="$csto" u {/rgb2}$comm"
${"-cs"}
um cs
fi
to_rgb endl a c endl done
fi
csswap_preview :
gui_split_preview "csswap $*",${-3--1}
Had to improve it just so it would perfectly work. There’s also more colour spaces, I noticed that @Reptorian and @afre had found some more so they deserve some thanks!
@Joan_Rake1 Let me know if you do a pull request. If you’d like, remove {} from if condition, and add spaces to make your code more understandable.
I tested it and it works! I’ll make a pull request soon - the next thing is the GUI options for the JPEG encoder…
@Joan_Rake1 Your cubism filter doesn’t work. Yes, I did deleted display code, but I don’t get a interesting result.
I have no idea how I’m gonna make that one work the way I want it to. The anti-aliasing is blocking any progress with that. Again, it can’t involve post-processing (that’s the challenge). I have no idea how I would do it in three dimensions.
In that case, I’m gonna comment it out, and right now it’s a backup code.
luv2rgb is missing. I might try to implement something, but I’m not sure how to reverse what David made.