-
Notifications
You must be signed in to change notification settings - Fork 161
Improvements to img2scad.html, fix contour() topic #1691
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@RAMilewski - Please check this version. In addition to edge detection, it also does sharpening. All the filters (blur, sharpen, edge detection) can be activated at once, and they feed into each other in that order, but that's unlikely to be how they'd be used. Sharpen and edge detection require a pre-blurred image, so if blur radius is set, those filters use that instead of their own internal blurring. If blur radius is zero, then sharpen does its own pre-blurring, and edge detection uses that instead of its own pre-blur. |
I'm confused.... Why do you blur before you sharpen? Seems counter-productive. |
The method for sharpening an image is to subtract the blurred image from the original. Therefore, blur before sharpen. Blurring gives you the low-frequency components of the image, and if you subtract that from the original with gradients in both directions amplified, you are left with high-frequency (sharper) components. (This is also why sharpening amplifies high-frequency noise in an image.) If you already blurred the image, then the sharpening uses that instead of blurring it internally. If you didn't blur the image yourself, it blurs the image internally before computing the difference. In reality, the three filters would likely be used independently, but if you set more than one of them, there has to be a cascade. For both sharpening and edge detection, blurring is the necessary first step. Edge detection can work with either the blurred or the sharpened one, because either way the blurring operation has already been done. Sharpening enhances high-frequency components, and edge detection would enhance the gradients (rate of change of brightness). If it would be less confusing, I can remove the cascade and put radio buttons in front of each filter, so you select only one of them, excluding the others. Actually the more I think about it, the more I think it would be a good idea to make the filters mutually exclusive. What do you think? |
The behavior of the sharpen filter seems strange to me. It dims the highlights quite a bit. |
Please upload an example file to test it on. Also do you think it's best if the three filters were all independent and didn't interact? If so, I'd just put radio buttons in front of each one so you can select the one you want. |
I see. That image is already sharp. You can see what's happening if you increase sharpening all the way to 20. You still have a white border next to the black outline. What this filter does is enhance the gradient (change in brightness) and then subtract low-frequency components. At the outer boundary of the figure in the drawing, you have a black edge next to a white background. This change is amplified, so then you have a "blacker" edge surrounded by a small "whiter" region. Internally, the brightness is just a number, and "blacker" is less than 0 and "whiter" is greater than 255, which cannot be displayed. After the sharpening operation is done, the new brightness range is rescaled back to the range 0-255. This results in the regions near the edge remaining white, but because they were greater than the white background before rescaling, the background is made grayer. Notice that the same thing happens with the black stripes on the headpiece. They turn from black to dark gray, because the black outline adjacent to the white background was made "blacker" (negative) internally before the brightness rescaling. |
Version 12 of img2scad.html committed. I'll add that the gray background you see from sharpening would affect only the height of the background in the texture relative to everything else. The edge of the figure would have a slight ridge before dropping in elevation to the black level. |
In img2scad.html:
In isosurface.scad:
contour()
module/function was classified under the wrong topic.