-
Notifications
You must be signed in to change notification settings - Fork 1
Add SVG filters to smooth spectrograms #251
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -748,6 +748,22 @@ export default defineComponent({ | |
|
|
||
| watch([backgroundColor, colorScheme], updateColorFilter); | ||
|
|
||
| function convMatrixFromOrder(order: number) { | ||
| let matrix = ''; | ||
| for (let i = 0; i < order; i++) { | ||
| for (let j = 0; j < order; j++) { | ||
| matrix += `1${j === order - 1 ? '': ' '}`; | ||
| } | ||
| matrix += `${i === order - 1 ? '' : '\n'}`; | ||
| } | ||
| return matrix; | ||
| } | ||
|
|
||
| // Knobs for testing blur filters | ||
| const contrast = ref({slope: 1.2, intercept: -0.1}); | ||
| const gaussianBlur = ref({ stdDeviation: 1.5 }); | ||
| const convolutionMatrix = ref({ order: 5 }); | ||
|
|
||
| return { | ||
| annotationState, | ||
| localAnnotations, | ||
|
|
@@ -757,6 +773,10 @@ export default defineComponent({ | |
| rValues, | ||
| gValues, | ||
| bValues, | ||
| contrast, | ||
| gaussianBlur, | ||
| convolutionMatrix, | ||
| convMatrixFromOrder, | ||
| }; | ||
| }, | ||
| }); | ||
|
|
@@ -796,7 +816,6 @@ export default defineComponent({ | |
| values="0" | ||
| result="grayscale" | ||
| /> | ||
|
|
||
| <!-- apply color scheme --> | ||
| <feComponentTransfer> | ||
| <feFuncR | ||
|
|
@@ -813,5 +832,182 @@ export default defineComponent({ | |
| /> | ||
| </feComponentTransfer> | ||
| </filter> | ||
| <filter id="spectro-smoothing-gaussian"> | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that there are now 3 separate filters with unique |
||
| <!-- convert to grayscale --> | ||
| <feColorMatrix | ||
| in="SourceGraphic" | ||
| result="grayscale" | ||
| type="saturate" | ||
| values="0" | ||
| /> | ||
| <!-- apply color scheme --> | ||
| <feComponentTransfer | ||
| in="grayscale" | ||
| out="colorscheme" | ||
| > | ||
| <feFuncR | ||
| type="table" | ||
| :tableValues="rValues" | ||
| /> | ||
| <feFuncG | ||
| type="table" | ||
| :tableValues="gValues" | ||
| /> | ||
| <feFuncB | ||
| type="table" | ||
| :tableValues="bValues" | ||
| /> | ||
| </feComponentTransfer> | ||
| <!-- Light gaussian blur --> | ||
| <feGaussianBlur | ||
| in="colorscheme" | ||
| :stdDeviation="gaussianBlur.stdDeviation" | ||
| result="blurred" | ||
| /> | ||
| <!-- increase contrast for defined edges --> | ||
| <feComponentTransfer | ||
| in="blurred" | ||
| result="contrasted" | ||
| > | ||
| <feFuncR | ||
| type="linear" | ||
| :slope="contrast.slope" | ||
| :intercept="contrast.intercept" | ||
| /> | ||
| <feFuncG | ||
| type="linear" | ||
| :slope="contrast.slope" | ||
| :intercept="contrast.intercept" | ||
| /> | ||
| <feFuncB | ||
| type="linear" | ||
| :slope="contrast.slope" | ||
| :intercept="contrast.intercept" | ||
| /> | ||
| </feComponentTransfer> | ||
| <!-- blend for even more refined edges --> | ||
| <feBlend | ||
| in="colorscheme" | ||
| in2="contrasted" | ||
| mode="overlay" | ||
| /> | ||
| </filter> | ||
| <filter id="spectro-smoothing-convo"> | ||
| <!-- convert to grayscale --> | ||
| <feColorMatrix | ||
| in="SourceGraphic" | ||
| result="grayscale" | ||
| type="saturate" | ||
| values="0" | ||
| /> | ||
|
|
||
| <!-- apply color scheme --> | ||
| <feComponentTransfer | ||
| in="grayscale" | ||
| out="colorscheme" | ||
| > | ||
| <feFuncR | ||
| type="table" | ||
| :tableValues="rValues" | ||
| /> | ||
| <feFuncG | ||
| type="table" | ||
| :tableValues="gValues" | ||
| /> | ||
| <feFuncB | ||
| type="table" | ||
| :tableValues="bValues" | ||
| /> | ||
| </feComponentTransfer> | ||
| <!-- Use a convolution matrix to blur --> | ||
| <feConvolveMatrix | ||
| in="colorscheme" | ||
| out="blurred" | ||
| :order="convolutionMatrix.order" | ||
| :kernelMatrix="convMatrixFromOrder(convolutionMatrix.order)" | ||
| :divisor="convolutionMatrix.order ** 2" | ||
| /> | ||
| <!-- blend for even more refined edges --> | ||
| <feBlend | ||
| in="colorscheme" | ||
| in2="blurred" | ||
| mode="overlay" | ||
| /> | ||
| </filter> | ||
| <filter id="spectro-smoothing-combined"> | ||
| <!-- convert to grayscale --> | ||
| <feColorMatrix | ||
| in="SourceGraphic" | ||
| result="grayscale" | ||
| type="saturate" | ||
| values="0" | ||
| /> | ||
| <!-- apply color scheme --> | ||
| <feComponentTransfer | ||
| in="grayscale" | ||
| out="colorscheme" | ||
| > | ||
| <feFuncR | ||
| type="table" | ||
| :tableValues="rValues" | ||
| /> | ||
| <feFuncG | ||
| type="table" | ||
| :tableValues="gValues" | ||
| /> | ||
| <feFuncB | ||
| type="table" | ||
| :tableValues="bValues" | ||
| /> | ||
| </feComponentTransfer> | ||
| <!-- light gaussian blur to remove pixelation --> | ||
| <feGaussianBlur | ||
| in="colorscheme" | ||
| :stdDeviation="gaussianBlur.stdDeviation" | ||
| result="gblurred" | ||
| /> | ||
| <!-- add blur via convolutional matrix --> | ||
| <feConvolveMatrix | ||
| in="gblurred" | ||
| out="mblurred" | ||
| :order="convolutionMatrix.order" | ||
| :kernelMatrix="convMatrixFromOrder(convolutionMatrix.order)" | ||
| :divisor="convolutionMatrix.order ** 2" | ||
| /> | ||
| <!-- Add contrast --> | ||
| <feComponentTransfer | ||
| in="mblurred" | ||
| out="contrasted" | ||
| result="contrasted" | ||
| > | ||
| <feFuncR | ||
| type="linear" | ||
| :slope="contrast.slope" | ||
| :intercept="contrast.intercept" | ||
| /> | ||
| <feFuncG | ||
| type="linear" | ||
| :slope="contrast.slope" | ||
| :intercept="contrast.intercept" | ||
| /> | ||
| <feFuncB | ||
| type="linear" | ||
| :slope="contrast.slope" | ||
| :intercept="contrast.intercept" | ||
| /> | ||
| </feComponentTransfer> | ||
| <!-- blend --> | ||
| <feBlend | ||
| in="SourceGraphic" | ||
| in2="contrasted" | ||
| mode="overlay" | ||
| result="blended" | ||
| /> | ||
| <!-- additional blurring? --> | ||
| <feGaussianBlur | ||
| in="blended" | ||
| stdDeviation="0.4" | ||
| /> | ||
| </filter> | ||
| </svg> | ||
| </template> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -121,7 +121,10 @@ const useGeoJS = () => { | |
| }); | ||
| } | ||
| clearQuadFeatures(); | ||
| quadFeatureLayer.node().css("filter", "url(#apply-color-scheme)"); | ||
| // quadFeatureLayer.node().css("filter", "url(#apply-color-scheme)"); | ||
| // quadFeatureLayer.node().css("filter", "url(#spectro-smoothing-gaussian)"); | ||
| // quadFeatureLayer.node().css("filter", "url(#spectro-smoothing-convo)"); | ||
| quadFeatureLayer.node().css("filter", "url(#spectro-smoothing-combined)"); | ||
|
Comment on lines
+124
to
+127
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Commented-out lines here refer to other filters. Currently the filter combines both techniques (gaussian blur and convolution matrix). For those interested, you can pick a different filter to use to compare. |
||
| for (let i = 0; i < imageCount; i += 1) { | ||
| quadFeatures.push(quadFeatureLayer.createFeature("quad")); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For anyone interested in exploring this branch, I've added this reactive state to the component for ease of testing changes.