Skip to content

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

Merged
merged 5 commits into from
May 31, 2025

Conversation

amatulic
Copy link
Contributor

@amatulic amatulic commented May 21, 2025

In img2scad.html:

  • Added size value to top of .scad output file
  • Added sharpening filter
  • Tweaked UI
  • Fixed artifact that appeared on image edge after applying Sobel edge detection filter, by making the convolutions use edge reflection

In isosurface.scad:

  • One comment line corrected. The contour() module/function was classified under the wrong topic.

@amatulic amatulic changed the title Add size value to top of img2scad.html output file Improvements to img2scad.html, fix contour() topic May 23, 2025
@amatulic
Copy link
Contributor Author

amatulic commented May 23, 2025

@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.

@RAMilewski
Copy link
Contributor

I'm confused.... Why do you blur before you sharpen? Seems counter-productive.

@amatulic
Copy link
Contributor Author

amatulic commented May 24, 2025

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?

@RAMilewski
Copy link
Contributor

The behavior of the sharpen filter seems strange to me. It dims the highlights quite a bit.

@amatulic
Copy link
Contributor Author

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.

@RAMilewski
Copy link
Contributor

Netfool

Note what happens to the background if you sharpen it.
Yes, I think the radio buttons would be a good idea.

@amatulic
Copy link
Contributor Author

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.

@amatulic
Copy link
Contributor Author

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.

@adrianVmariano adrianVmariano merged commit 5a6a4b9 into BelfrySCAD:master May 31, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants