-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #165 from sandboxnu/sobel-filter
Sobel filter
- Loading branch information
Showing
15 changed files
with
371 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+36.4 KB
src/media/modules/computerVision/sobelKernels/diagonaldown_darktolight.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+36.3 KB
src/media/modules/computerVision/sobelKernels/diagonaldown_lighttodark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+36.3 KB
src/media/modules/computerVision/sobelKernels/diagonalup_darktolight.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+36.2 KB
src/media/modules/computerVision/sobelKernels/diagonalup_lighttodark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+33.9 KB
src/media/modules/computerVision/sobelKernels/horizontal_darktolight.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+33.5 KB
src/media/modules/computerVision/sobelKernels/horizontal_lighttodark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+35.3 KB
src/media/modules/computerVision/sobelKernels/vertical_darktolight.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+35.4 KB
src/media/modules/computerVision/sobelKernels/vertical_lighttodark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
173 changes: 173 additions & 0 deletions
173
src/modules/computerVision/sobelFilter/SobelFilterDemo.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
/* eslint-disable */ | ||
|
||
import React, { useLayoutEffect, useRef, useState, useEffect } from "react"; | ||
import { | ||
gradientImages, | ||
GradientsType | ||
} from "./sobelFilter"; | ||
import vertDarkLightKernel from "../../../media/modules/computerVision/sobelKernels/vertical_darktolight.png"; | ||
import vertLightDarkKernel from "../../../media/modules/computerVision/sobelKernels/vertical_lighttodark.png"; | ||
import horizDarkLightKernel from "../../../media/modules/computerVision/sobelKernels/horizontal_darktolight.png"; | ||
import horizLightDarkKernel from "../../../media/modules/computerVision/sobelKernels/horizontal_lighttodark.png"; | ||
import diagDownDarkLightKernel from "../../../media/modules/computerVision/sobelKernels/diagonaldown_darktolight.png"; | ||
import diagDownLightDarkKernel from "../../../media/modules/computerVision/sobelKernels/diagonaldown_lighttodark.png"; | ||
import diagUpDarkLightKernel from "../../../media/modules/computerVision/sobelKernels/diagonalup_darktolight.png"; | ||
import diagUpLightDarkKernel from "../../../media/modules/computerVision/sobelKernels/diagonalup_lighttodark.png"; | ||
|
||
type GradientImageType = { | ||
label: string; | ||
gradient: ImageData; | ||
width: number; | ||
height: number; | ||
labelColor: string; | ||
}; | ||
|
||
export const GradientImage: React.FC<GradientImageType> = ({ | ||
label, | ||
gradient, | ||
width, | ||
height, | ||
labelColor, | ||
}) => { | ||
const canvasRef = useRef<HTMLCanvasElement>(null); | ||
|
||
useEffect(() => { | ||
const cnvElm = canvasRef.current; | ||
if (!cnvElm) return; | ||
createImageBitmap(gradient).then(img => | ||
cnvElm | ||
.getContext('2d') | ||
?.drawImage(img, 0, 0, cnvElm.width, cnvElm.height), | ||
); | ||
}); | ||
|
||
return ( | ||
<div className="my-auto mx-3"> | ||
<p className={`${labelColor} md:hidden`}>{label}</p> | ||
<canvas | ||
className="crisp-pixels mx-auto sobel-image-width" | ||
ref={canvasRef} | ||
width={width} | ||
height={height} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
type SobelFilterRowType = { | ||
label: string, | ||
labelColor: string, | ||
darkLightImage: ImageData, | ||
lightDarkImage: ImageData, | ||
darkLightKernelSrc: string, | ||
lightDarkKernelSrc: string | ||
} | ||
|
||
const SobelFilterRow: React.FC<SobelFilterRowType> = ({ | ||
label, | ||
labelColor, | ||
darkLightImage, | ||
lightDarkImage, | ||
darkLightKernelSrc, | ||
lightDarkKernelSrc | ||
}) => { | ||
return ( | ||
<div className="my-3"> | ||
<p className={`text-3xl ${labelColor}`}>{label}</p> | ||
<div className="flex flex-col md:flex-row justify-evenly "> | ||
<GradientImage | ||
label="Dark to Light" | ||
gradient={darkLightImage} | ||
width={darkLightImage.width} | ||
height={darkLightImage.height} | ||
labelColor={labelColor} | ||
/> | ||
<div className="my-auto mx-auto"> | ||
<img src={darkLightKernelSrc} alt="img" className={`min-w-20vw ${labelColor === "text-modulePaleBlue" ? "img-invert" : ""}`} /> | ||
</div> | ||
<div className="my-auto mx-auto"> | ||
<img src={lightDarkKernelSrc} alt="img" className={`min-w-20vw ${labelColor === "text-modulePaleBlue" ? "img-invert" : ""}`} /> | ||
</div> | ||
<GradientImage | ||
label="Light to Dark" | ||
gradient={lightDarkImage} | ||
width={lightDarkImage.width} | ||
height={lightDarkImage.height} | ||
labelColor={labelColor} | ||
/> | ||
</div> | ||
</div> | ||
) | ||
}; | ||
|
||
type SobelFilterDemoType = { | ||
labelColor: string; | ||
imgUrl: string; | ||
}; | ||
|
||
const SobelFilterDemo: React.FC<SobelFilterDemoType> = ({ | ||
labelColor, | ||
imgUrl, | ||
}) => { | ||
const imgRef = useRef<HTMLImageElement>(null); | ||
const [gradients, setGradients] = useState<GradientsType>(); | ||
|
||
const img = useRef(''); | ||
const config = useRef(''); | ||
|
||
useLayoutEffect(() => { | ||
// reset to tab 0 when changing images | ||
if (img.current !== imgUrl) { | ||
gradientImages(imgUrl).then(gradients => setGradients(gradients)); | ||
} | ||
img.current = imgUrl; | ||
}); | ||
|
||
return ( | ||
|
||
<div> | ||
<p className={`text-3xl ${labelColor}`}>Original Image</p> | ||
<img ref={imgRef} src={imgUrl} alt="img" className="mx-auto sobel-image-width" /> | ||
|
||
{gradients && | ||
<div className='my-10'> | ||
<SobelFilterRow | ||
label="Vertical Edges" | ||
labelColor={labelColor} | ||
darkLightImage={gradients.vertDarkLight} | ||
lightDarkImage={gradients.vertLightDark} | ||
darkLightKernelSrc={vertDarkLightKernel} | ||
lightDarkKernelSrc={vertLightDarkKernel} | ||
/> | ||
<SobelFilterRow | ||
label="Horizontal Edges" | ||
labelColor={labelColor} | ||
darkLightImage={gradients.horizDarkLight} | ||
lightDarkImage={gradients.horizLightDark} | ||
darkLightKernelSrc={horizDarkLightKernel} | ||
lightDarkKernelSrc={horizLightDarkKernel} | ||
/> | ||
<SobelFilterRow | ||
label="Diagonal Down Edges" | ||
labelColor={labelColor} | ||
darkLightImage={gradients.diagDownDarkLight} | ||
lightDarkImage={gradients.diagDownLightDark} | ||
darkLightKernelSrc={diagDownDarkLightKernel} | ||
lightDarkKernelSrc={diagDownLightDarkKernel} | ||
/> | ||
<SobelFilterRow | ||
label="Diagonal Up Edges" | ||
labelColor={labelColor} | ||
darkLightImage={gradients.diagUpDarkLight} | ||
lightDarkImage={gradients.diagUpLightDark} | ||
darkLightKernelSrc={diagUpDarkLightKernel} | ||
lightDarkKernelSrc={diagUpLightDarkKernel} | ||
/> | ||
</div> | ||
} | ||
|
||
</div> | ||
); | ||
}; | ||
|
||
export default SobelFilterDemo; |
Oops, something went wrong.
73bc898
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.
Successfully deployed to the following URLs: