java中shapes中Mypic画图_Java LineAndShapeRenderer.setShapesVisible方法代码示例

本文介绍了一个使用Java和JFreeChart库创建线形图表的方法。该图表用于展示受害者通知、分配和救援的时间序列数据,通过定制化的图表样式和布局增强数据可视化效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

import org.jfree.chart.renderer.category.LineAndShapeRenderer; //导入方法依赖的package包/类

public JFreeChart crearLineChartAsignRescateVict(CategoryDataset dataset) {

chartNotifAsigResc = ChartFactory.createLineChart(

"Tiempos de Notificaci�n, asiganci�n y Rescate de Victimas ", // chart title Titulo local del grafico

"Victimas Ordenadas por tiempo de rescate ", // x axis label

"Tiempo milisegundos", // y axis label

dataset, // data

PlotOrientation.VERTICAL,

true, // include legend

true, // tooltips

false // urls

);

// NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

ChartPanel chartPanel = new ChartPanel(chartNotifAsigResc);

// chartNotifAsigResc.setBackgroundPaint(Color.white);

CategoryPlot plot = (CategoryPlot) chartNotifAsigResc.getPlot();

// CategoryPlot plot = chartNotifAsigResc.getCategoryPlot();

// plot.setBackgroundPaint(Color.lightGray);

// plot.setDomainGridlinePaint(Color.white);

// plot.setRangeGridlinePaint(Color.white);

// NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();

// rangeAxis.setUpperMargin(0.15);

CategoryItemRenderer renderer = plot.getRenderer();

renderer.setItemLabelGenerator(new LabelGenerator(50.0));

renderer.setItemLabelFont(new Font("Serif", Font.PLAIN, 8));

renderer.setItemLabelsVisible(true);

// CategoryPlot plot = (CategoryPlot) chartNotifAsigResc.getPlot();

LineAndShapeRenderer rendererl = (LineAndShapeRenderer) plot.getRenderer();

rendererl.setShapesVisible(true);

rendererl.setDrawOutlines(true);

rendererl.setUseFillPaint(true);

rendererl.setFillPaint(Color.white);

chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));

setContentPane(chartPanel);

this.pack();

RefineryUtilities.centerFrameOnScreen(this);

this.setVisible(true);

return chartNotifAsigResc;

}

### Labelme 库中 `shapes_to_label` 和 `lblsave` 函数的使用 #### shapes_to_label 方法解析 `labelme.utils.shapes_to_label` 是用于将由Labelme生成的JSON文件中的形状(多边形、矩形等)转换成标签掩码图像的方法。此方法接受多个参数,包括图像尺寸、形状列表以及类别名称到ID映射字典。 ```python import numpy as np from labelme import utils def convert_shapes_to_labels(img_shape, shapes, label_name_to_value): lbl, _ = utils.shapes_to_label( img_shape=img_shape, shapes=shapes, label_name_to_value=label_name_to_value ) return lbl ``` 上述代码展示了如何定义一个辅助函数来调用 `utils.shapes_to_label()` 并返回标签数组 `lbl`[^1]。 #### lblsave 函数介绍 `labelme.utils.lblsave` 则是用来保存标签掩码图像至磁盘上的PNG文件。该功能可以方便地把处理后的二值化或彩色编码的结果存储下来以便后续查看或者作为模型输入的一部分。 ```python from PIL import Image import os.path as osp from labelme import utils def save_label_as_png(filename, lbl): if osp.splitext(filename)[1] != '.png': filename += '.png' # Ensure the directory exists. dirname = osp.dirname(filename) if not osp.exists(dirname): os.makedirs(dirname) utils.lblsave(filename, lbl.astype(np.int32)) ``` 这段脚本说明了怎样创建一个新的实用程序函数 `save_label_as_png()`, 它接收目标路径名和标签矩阵两个参数,并利用 `utils.lblsave()` 将其写入指定位置。 #### 实际应用案例展示 下面给出一段完整的Python代码片段,它读取了一个LabelMe JSON文件并将其转化为对应的标签图再保存: ```python import json import cv2 import numpy as np from pathlib import Path from labelme import utils json_file = './example.json' # 替换成实际存在的Labelme标注文件路径 output_dir = './converted/' # 输出目录 with open(json_file) as f: data = json.load(f) img_data = cv2.imread(str(Path(json_file).parent / data['imagePath'])) height, width = img_data.shape[:2] # 构建从类名到索引编号之间的对应关系表 label_names = ['__background__'] + [shape['label'] for shape in set([tuple(shape.items()) for shape in data['shapes']])] label_values = list(range(len(label_names))) label_map = dict(zip(label_names, label_values)) # 调用API完成转化工作 label_img = utils.shapes_to_label((height, width), data['shapes'], label_map) # 存储结果 utils.lblsave(output_dir + 'result.png', label_img) print('Conversion completed.') ``` 以上示例实现了从加载原始标注数据到最后一步输出最终标签图像的过程。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值