在MATLAB中确定区域平均值 [英] Determine a regions average in MATLAB

查看:2518
本文介绍了在MATLAB中确定区域平均值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些图像中RGB捕获的帮助。
我正在使用impixel来手动从图片中获取RGB,但我想创建一个网格,比方说20x20像素盒,它会自动告诉我每个盒子的RGB值。所以在一张图片中我可以说我有20个盒子它会告诉我20个RGB值。是的,如果有20%或更多的空白区域,它会忽略那个rgb框。

I need some help with RGB capture in a image. I am using impixel to manualy get RGB from a picture, but i would like to create a grid of let's say 20x20 px boxes where it will automatically tell me for each box a RGB value. So in a picture lets say i have 20 boxes it will tell me 20 RGB values. Yeah an if there is 20% or more of white space that it ignores that rgb box.

你能指点我一些链接或者给我一个大致的想法怎么做这个。

Can you point me to some links or give me a general idea how to do this.

祝你好运

PS图像只是一个.jpg,背景是白色,中间有一个项目。

P.S. image is just a .jpg, the background is white an in the middle there is an item.

UPDATE

这是我使用impixel收集RGB的代码

This is my code for collecting RGB using impixel

px=impixel(img);        
st = num2cell(px,1);
zstup = cellfun(@sum,st); 
zred = size(px,1);         
rez = bsxfun(@rdivide,zstup,zred); 
trez=round(rez); 

我想做的是:

http://imageshack.us/photo/my-images/696/exsample .jpg /

所以像A1,A2等这样的每一个框都会在我的代码中返回RGB值,如trez。

So every box like A1, A2, and so on will return RGB value like trez in my code.

因此,在我的代码中,我将 trez 数据保存在表中,就像在excell中说的那样220 | 23 | 34,现在如果我那样做另一种水果我会有

So in my code i save my trez data in a table and it is like in excell lets say 220 | 23 | 34, now if i do that to another fruit i will have

220 | 23 | 34

220 | 23 | 34

123 | 212 | 78

123 | 212| 78

依旧......

回归自动化,A7和A 15不会很好RGB canditades因为它们有超过50%的白色区域所以具有20%白色的所有东西都将被忽略。
所以A31是好的,需要保存RGB值。

Returning to automatization, A7 and A 15 would not be good RGB canditades because they have more then 50% white area so everything that has 20% white will be ignored. So A31 is good and the RGB value needs to be saved.

所以总而言之,我将拥有6个RGB值,这些必须是像上面的例子一样自动保存。
我知道如何保存到表格我只需要帮助收集每个框中的rgb值。

So all in all here i would have my be 6 RGB values that would have to be automatically saved like the above example. I know how to save to table i just need help for the gathering rgb values in every box.

推荐答案

取决于根据您的确切需求,我看到两种解决方案:

Depending on your exact needs I see two solutions:

使用 impyramid(img,'reduce')缩小图像尺寸。这样可以为您提供由原始图像的平均值组成的较小图像。然后执行您之前执行的操作以访问单个像素。根据需要重复以获得2x2,4x4,8x8或更大的盒子。

Downscale the image using impyramid(img, 'reduce'). This gives you a smaller image consisting of average values of the original image. Then do what you did before to access single pixels. Repeat as often as necessary to get 2x2, 4x4, 8x8 or larger "boxes".

或者你可以使用定义一个盒子(或任意形状)作为一个矩阵和零,并使用 regionprops 函数,以获取有关图像内容的信息,具体取决于包含的字段:

Or you could use define a box (or arbitrary shape) as a matrix of ones and zeros and use the regionprops function in order to get information about the images content depending on the fields containing ones:

roi = zeros(size(img))
roi(1:10,1:10) = 1;
r = regionprops(roi, img, 'MeanIntensity')
average = r.MeanIntensity

这篇关于在MATLAB中确定区域平均值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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