Open yang-junhua opened 8 months ago
It would depend on how you're presenting the image (i.e. where is the UI being provided?). If you try the 'cut-out' feature on that demo page, you can directly copy the CSS that's applied to the little cut-outs that appear on the far left menu:
.sticker:hover, .sticker-select {
filter: drop-shadow(0.25rem 0.25rem 1px #2962d9)
drop-shadow(-0.25rem 0.25rem 1px #2962d9)
drop-shadow(0.25rem -0.25rem 1px #2962d9)
drop-shadow(-0.25rem -0.25rem 1px #2962d9);
}
You have to dig through the browser inspect window (i.e. hit F12 on chrome/firefox at least) a bit, but you can toggle that CSS on/off and see the effect appear/disappear. So that's one way to do it, if you're using a web-based UI.
If you wanted to do it within python, there's an explanation of how to modify one of the notebooks to get a similar-ish outline effect in issue #589.
What I want is to click on the mask and see what it looks like.
Clicking the mask will generate an svg element (with the picture).Can you tell me how to generate an svg element? How the code is implemented.Thank you very much.
In python, you can generate an outline from the SAM mask using:
mask_contours, _ = cv2.findContours(uint8_mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
Where the uint8_mask
is the mask from SAM, converted to uint8 (so dark areas have values of 0 and the segmentation has a value of 255). This gives you polygon(s) which would need to be converted to svg. There seem to be some python libraries that can make svgs, but if you're displaying in a browser, then sending the polygon data to the browser and using something like d3 to make the svg path may be more flexible.
<radialGradient id="gradient" cx="0" cy="0" r="487" gradientUnits="userSpaceOnUse" gradientTransform="translate(282.25,375.5)"><stop offset="0" stop-color="white" stop-opacity="0"></stop><stop offset="0.25" stop-color="white" stop-opacity="0.7"></stop><stop offset="0.5" stop-color="white" stop-opacity="0"></stop><stop offset="0.75" stop-color="white" stop-opacity="0.7"></stop><stop offset="1" stop-color="white" stop-opacity="0"></stop><animateTransform attributeName="gradientTransform" attributeType="XML" type="scale" from="0" to="12" dur="1.5s" begin=".3s" fill="freeze" additive="sum"></animateTransform></radialGradient>
The radial gradient looks like it's used to generate the flashing animation that appears after creating a mask:
The r
value they use is probably just an aesthetic choice to make the animation look nice, I don't know if it's calculated from anything (although I guess it could be chosen based on the size of the segmentation).
Demo url:https://segment-anything.com/demo
Can you tell me how to achieve the image effect? Thank you so much.