如何在matlab中实现直方图均衡的一部分,而不使用for循环并影响速度和性能 [英] How to implement a part of histogram equalization in matlab without using for loops and influencing speed and performance

查看:298
本文介绍了如何在matlab中实现直方图均衡的一部分,而不使用for循环并影响速度和性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我在matlab中有这三个变量变量

b $ b我想在NewGrayLevels中提取不同的值,并将OldHistogram的行与一个不同的值在同一行中相加。

例如,你在NewGrayLevels中看到六个第一行等于零。这意味着NewGrayLevels中的0值取自OldGrayLevels的(0 1 2 3 4 5)。所以OldHistogram中的相应行应该相加。

所以0 + 2 + 12 + 38 + 113 + 163 = 328将是均衡直方图中灰度等级0的频率,依此类推。 >
熟悉图像处理的人都知道它是直方图均衡算法的一部分。

请注意,我不想使用图像处理工具箱中提供的内置函数histeq我想自己实现它。

我知道如何用for循环编写算法。我正在寻找是否有更快的方法而不使用for循环。

使用for循环的代码:

Suppose that I have these Three variables in matlab Variables
I want to extract diverse values in NewGrayLevels and sum rows of OldHistogram that are in the same rows as one diverse value is.
For example you see in NewGrayLevels that the six first rows are equal to zero. It means that 0 in the NewGrayLevels has taken its value from (0 1 2 3 4 5) of OldGrayLevels. So the corresponding rows in OldHistogram should be summed.
So 0+2+12+38+113+163=328 would be the frequency of the gray level 0 in the equalized histogram and so on.
Those who are familiar with image processing know that it's part of the histogram equalization algorithm.
Note that I don't want to use built-in function "histeq" available in image processing toolbox and I want to implement it myself.
I know how to write the algorithm with for loops. I'm seeking if there is a faster way without using for loops.
The code using for loops:

   for k=0:255
       Condition = NewGrayLevels==k;
       ConditionMultiplied = Condition.*OldHistogram;
       NewHistogram(k+1,1) = sum(ConditionMultiplied);
   end  

如果此代码对于高分辨率大图像变慢,我担心。因为我上传的变量是从互联网上下载的小图片,但我的代码可能用于sattellite图像。

I'm afraid if this code gets slow for high resolution big images.Because the variables that I have uploaded are for a small image downloaded from the internet but my code may be used for sattellite images.

推荐答案

我明白没有必要编写@Hugh Nolan建议的代码。请参阅此处的解释:

Well I understood that there's no need to write the code that @Hugh Nolan suggested. See the explanation here:

%The green lines are because after writing the code, I understood that  
%there's no need to calculate the equalized histogram in  
%"HistogramEqualization" function and after gaining the equalized image  
%matrix you can pass it to the "ExtractHistogram" function  
% (which there's no loops in it) to acquire the  
%equalized histogram.    
%But I didn't delete those lines of code because I had tried a lot to  
%understand the algorithm and write them.  

有关更多信息和研究代码,请参阅我的下一个问题。

For more information and studying the code, please see my next question.

这篇关于如何在matlab中实现直方图均衡的一部分,而不使用for循环并影响速度和性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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