In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the relevant knowledge of "how to achieve anti-threshold binarization in OpenCV". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Inverse threshold binarization
Inverse threshold binarization and threshold binarization are inverse operations each other. The implementation of this class in OpenCV depends on the threshold () function. The following is the declaration of the function:
Threshold (src, dst, thresh, maxval, type)
Interpretation of each parameter
Src
A Mat object that represents the source of this operation (the input image).
Mat
An object like Mat that represents the target (output) image.
Thresh
Represents the threshold T.
Maxval
Represents the maximum grayscale value, usually 255.
Type
An integer type variable that represents the type of threshold to use, and the inverse threshold binarization is Imgproc.THRESH_BINARY_INV.
The mathematical description is explained as follows:
For a given src (XQuery y), if its pixel value is greater than the threshold T (thresh), it returns 0, otherwise it is the maximum pixel value.
Then the pixel description of dst is as follows:
Java code (JavaFX Controller layer)
Public class Controller {@ FXML private Text fxText; @ FXML private ImageView imageView; @ FXML private Label resultLabel; @ FXML public void handleButtonEvent (ActionEvent actionEvent) throws IOException {Node source = (Node) actionEvent.getSource (); Window theStage = source.getScene () .getWindow (); FileChooser fileChooser = new FileChooser (); FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter ("PNG files (* .png)", "* .png") FileChooser.getExtensionFilters () .add (extFilter); fileChooser.getExtensionFilters () .add (new FileChooser.ExtensionFilter ("JPG Files (* .jpg)", "* .jpg")); File file = fileChooser.showOpenDialog (theStage); runInSubThread (file.getPath ()) } private void runInSubThread (String filePath) {new Thread (new Runnable () {@ Override public void run () {try {WritableImage writableImage = thresholdOfNonBinary (filePath)) Platform.runLater (new Runnable () {@ Override public void run () {imageView.setImage (writableImage);}});} catch (IOException e) {e.printStackTrace () }) .start ();} private WritableImage thresholdOfNonBinary (String filePath) throws IOException {System.loadLibrary (Core.NATIVE_LIBRARY_NAME); Mat src = Imgcodecs.imread (filePath); Mat dst = new Mat (); Imgproc.threshold (src, dst, 130,255, Imgproc.THRESH_BINARY_INV); MatOfByte matOfByte = new MatOfByte () Imgcodecs.imencode (".jpg", dst, matOfByte); byte [] bytes = matOfByte.toArray (); InputStream in = new ByteArrayInputStream (bytes); BufferedImage bufImage = ImageIO.read (in); WritableImage writableImage = SwingFXUtils.toFXImage (bufImage, null); return writableImage;}}
Operation diagram
This is the end of the content of "how to achieve anti-threshold binarization in OpenCV". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.