【问题标题】:Normalization of a plot图的标准化
【发布时间】:2018-04-09 03:46:08
【问题描述】:

我需要将绘图标准化为从 0 到 255 的灰度。数据为 .txt 格式。这是我的粗略绘图:

clf;
%call importdata() after changing current directory
B = importdata('sigpros.txt');

d  = 1000; %vertical spacing
Bs = B;    %copy of the original data

for i = 1 : size(Bs,2)
    %loop adding constant to each column
    Bs(:,i) = Bs(:,i) + (i-1) * d;
end    

%plot the modified matrix
plot(Bs);

数据由 349 行和 4007 列组成。每列都是完整的 A 扫描数据(波形)。每个数据都有一个垂直间距,所有这些绘制的数据构成 B 扫描数据(从传感器位移获得的波形)。我不确定上面的代码是否正确,但数据应该类似于:B-Scan data

这可以通过将上面的矩阵图标准化为 0 到 255 的灰度来实现。目前,这就是我的图的样子:My plot。请帮助我获得所需的 B 扫描图,如上图所示!谢谢!

更新

这是normalized b-scan data。但是,它最初达到峰值的方式高于上图中的方式。这里可能是什么问题?

零偏移消除

clf;
%call importdata() after changing current directory
B = importdata('A_scan1.txt');
Bd = detrend(B,0); %remove the zero offset

d  = 1000; %vertical spacing
Bs = Bd;    %copy of the original data

for i = 1 : size(Bs,2)
    %loop adding constant to each column
    Bs(:,i) = Bs(:,i) + (i-1) * d;
end    

minV = min(Bs(:));
maxV = max(Bs(:));
Bs_scale = (Bs-minV)*255/(maxV-minV);

%plot the modified matrix
plot(Bs_scale, 'k');

但是,它仍然不是从 0 开始的。

【问题讨论】:

  • 我不完全理解您的要求。查看 2 个图,唯一的区别(除了更多的线)是你的图是彩色的。您只想将所有线条变为黑色或灰色吗?如果是这样就这样做plot(Bs,'k');
  • 我还需要将绘图标准化为 0 到 255 .. 这就是我被告知的。有什么方法可以标准化矩阵图?
  • 我不确定您希望它如何标准化。您可以重新调整所有内容,使 Bs 的最大值变为 255,然后 Bs 的最小值变为 0。注意:目前,您的两个示例图中都有一些负值,因此将应用偏移量。
  • 类似这样的东西:minV = min(Bs(:)); maxV = max(Bs(:)); Bs_scale = (Bs-minV)*255/(maxV-minV); 然后plot(Bs_scale,'k'); ...如果那是你的意思,我可以把它放在答案中...但似乎有点武断.
  • 为什么是任意的?我可以试试你的做法,我会通知你的。

标签: matlab plot matlab-figure normalization


【解决方案1】:

这将设置偏移量,因此第一行的起点为零并缩放所有数据,使从最小值到最大值的范围为 255 个单位。

我注释掉了,但包含了一些可以替代缩放数据的行,使其从 0 开始,峰值在 255。但是,由于您有一些负值,因此总范围 > 255。

clf;
%call importdata() after changing current directory
B = importdata('sigpros.txt');

%NOTE: I am only plotting the first 59 lines as the rest don't look as good
Bd = detrend(B(:,1:59),0); %remove the zero offset

d  = 1000; %vertical spacing
Bs = Bd;    %copy of the original data

%Get the initial zero offset from the first line
initOffset = Bs(1,1);
%% xxx Alternatively take the mean across all starting points xxx
% initOffset = mean(Bs(1,:));

for i = 1 : size(Bs,2)
    %loop adding constant to each column
    Bs(:,i) = Bs(:,i) - initOffset + (i-1) * d ; %subtract the offset from each
end    

minV = min(Bs(:));
maxV = max(Bs(:));

%This make the RANGE from min to make = 0-255 units.
Bs_scale = (Bs)*255/(maxV-minV);
%% xxxx If instead you want the peak to be at 255 xxxxx
% Bs_scale = (Bs)*255/(maxV);

%plot the modified matrix
plot(Bs_scale, 'k');

编辑/解释:

Here is what B looks like Raw.。它基本上是一系列相互重叠的线。在您detrend 之后,它会删除大部分常量偏移量。 然而,由于这个信号不是完全对称的,这些线并不完全从零开始……它们比以前更接近,但并不完美。 Here is Bd detrend 之后的Here is Bd 请注意,每一行并不是从零开始。

接下来,您的 for 循环最初通过添加 d so it looked like this 的倍数将每行间隔 1000。由于这些行并不完全从零开始,这是您要求的,我添加了初始偏移项。这些基本上取第一行的第一个点,并从每一行中减去它。从而迫使它从零开始。

【讨论】:

  • 能否详细说明 initOffset = Bs(1,1);修复了零偏移?谢谢
  • 查看编辑以获取解释
猜你喜欢
  • 2022-01-12
  • 1970-01-01
  • 1970-01-01
  • 2017-07-20
  • 2017-03-31
  • 2010-10-14
  • 2018-10-20
  • 2020-09-08
  • 1970-01-01
相关资源
最近更新 更多