📜  节点 | GM段()函数

📅  最后修改于: 2022-05-13 01:56:57.088000             🧑  作者: Mango

节点 | GM段()函数

segment()函数是 GraphicsMagick 库中的一个内置函数,用于通过分析颜色分量的直方图和使用模糊 c 均值技术识别同质单元来分割图像。该函数在成功时返回真值。

句法:

threshold( cluster threshold, smoothing threshold )

参数:此函数接受两个参数,如上所述,如下所述:

  • 集群阈值:该参数用于指定集群阈值的值。
  • 平滑阈值:该参数用于指定平滑阈值的值。

返回值:此函数返回 GraphicsMagick 对象。

示例 1:



Javascript
// Include gm library
var gm = require('gm');
 
//Import the image
gm(600, 300, 'white')
 
// set the color for the stroke
.stroke("green", 3)
 
// Set the font
.font("Helvetica.ttf", 60)
 
//Call to drawText Function
.drawText(100, 280, "GeeksforGeeks!")
 
// Invoke segment function
.segment(1, 0.1)
 
// Process and write the image
.write("segment1.png", function (err) {
  if (!err) console.log('done');
});


Javascript
// Include gm library
var gm = require('gm');
 
// Import the image
gm('1.png')
 
// Invoke segment function with 2, 0.2
.segment(2, 0.2)
 
// Process and Write the image
.write("segment1.png", function (err) {
  if (!err) console.log('done');
});


输出:

示例 2:

Javascript

// Include gm library
var gm = require('gm');
 
// Import the image
gm('1.png')
 
// Invoke segment function with 2, 0.2
.segment(2, 0.2)
 
// Process and Write the image
.write("segment1.png", function (err) {
  if (!err) console.log('done');
});

输出:

参考:

  • http://www.graphicsmagick.org/GraphicsMagick.html#details-rotate
  • https://www.npmjs.com/package/gm