从图像中删除空格周围 [英] Remove surrounding whitespace from an image

查看:106
本文介绍了从图像中删除空格周围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,我们收到来自客户的产品图片块。每个产品形象的东西的图片,它是采取一个白色背景。我想裁剪图像的所有周围的部分,但只留下了产品在中间。这可能吗?

I have a block of product images we received from a customer. Each product image is a picture of something and it was taken with a white background. I would like to crop all the surrounding parts of the image but leave only the product in the middle. Is this possible?

作为一个例子:<一href=\"http://www.5dnet.de/media/catalog/product/d/r/dress_shoes_5.jpg%5d%5b1%5d\">http://www.5dnet.de/media/catalog/product/d/r/dress_shoes_5.jpg][1]

我不希望所有白色像素去掉,但我还是希望图像裁剪,使像素的最上面一行包含一个非白色像素,像素的最左边的竖行包含一个非白色像素,像素最下面的水平行包含一个非白色像素,等等。

I don't want all white pixels removed, however I do want the image cropped so that the top-most row of pixels contains one non-white pixel, the left-most vertical row of pixels contains one non-white pixel, bottom-most horizontal row of pixels contains one non-white pixel, etc.

在C#或VB.net code将AP preciated。

Code in C# or VB.net would be appreciated.

推荐答案

我已经写了code这样做自己 - 这不是太难以得到基本去。

I've written code to do this myself - it's not too difficult to get the basics going.

从本质上讲,你需要扫描像素行/列检查非白色像素和隔离产品形象的边界,然后创建一个新的位图只有该区域。

Essentially, you need to scan pixel rows/columns to check for non-white pixels and isolate the bounds of the product image, then create a new bitmap with just that region.

请注意,虽然 Bitmap.GetPixel()方法的工作,这是比较慢的。如果处理时间是非常重要的,你需要使用 Bitmap.LockBits()锁定内存中的位图,然后一个不安全{} 块直接访问像素。

Note that while the Bitmap.GetPixel() method works, it's relatively slow. If processing time is important, you'll need to use Bitmap.LockBits() to lock the bitmap in memory, and then some simple pointer use inside an unsafe { } block to access the pixels directly.

<一个href=\"http://www.$c$cproject.com/KB/GDI-plus/csharpgraphicfilters11.aspx?fid=3488&df=90&mpp=25&noise=3&sort=Position&view=Quick&fr=76&select=1123224\"相对=nofollow>在$ C $的CProject本文给出了一些细节,你可能会发现有用的。

This article on CodeProject gives some more details that you'll probably find useful.

这篇关于从图像中删除空格周围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆