自动裁剪图片
我有很多由黑色背景物体组成的图片。我用 Matlab 创建了它们,它们的图片周围都有一个白色的“额外”。我希望能够自动裁剪它们,以便图片不会有多余的白色。
文件为 .tif
格式
这里以图片为例:
>一开始可能不太明显,但如果您选择图片,它会比黑色区域大得多。
I have many pictures that are made of an object with black background. I've created them with Matlab, and they all have a white "extra" surrounding the picture. I want to be able to automatically crop them so that the picture will not have the white extra.
The files are .tif
format
Here is a picture as an example:
It may be not noticeable at first, but if you select the picture, it's much bigger than just the black area.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以简单地丢弃只有行和列的行和列。
对于 RGB tiff,您可以使用(假设 tiff 图像中的最大值为 86,如 png)
编辑
有几种方法可以确保您不会在图像中出现边框首位。例如,如果要保存 M×N×3 RGB 图像数组,可以使用 IMWRITE 进行书写
或者,如果您想保存没有边框的图形,您可以调用 GETFRAME 在轴句柄上获取图像:
如果你想用抗锯齿保存你的图形,你可以使用优秀的 export_fig 来自文件交换。
You can simply throw away the rows and columns in which you have only ones.
For RGB tiffs, you can use (assuming that the max value in the tiff image is 86, as in the png)
EDIT
There are a few ways to ensure that you don't get the border in the first place. For example, if you want to save an M-by-N-by-3 RGB image array, you can use IMWRITE to write
Alterantively, if you have a figure you'd like to save without the border, you can call GETFRAME on the axes handle to obtain the image:
If you want to save your figure with anti-aliasing, you can use the excellent export_fig from the file exchange.