【问题标题】:Matlab - Plotting Specific Pixels (image treatment)Matlab - 绘制特定像素(图像处理)
【发布时间】:2020-02-24 13:19:37
【问题描述】:

我目前正在努力解决图像处理\数据绘图问题,并希望在这件事上从比我更有经验的人那里获得一些反馈。

我会尝试分解问题以使其更容易理解:

  1. 我有一个大小为 NxM 的原始图像(figureB - 这是原始图像的蓝色通道),我从该图像中选择一个特定区域进行研究(NewfigureB ),尺寸 120x170;

  2. 然后我将这个区域划分为我所谓的宏像素,它们是 10x10 的数据点(像素)阵列;

  3. 然后我将蒙版应用到选定区域以仅选择满足某些发光条件的点;

到目前为止一切顺利。当我在应用发光蒙版时尝试绘制每个宏像素的直方图时,我的问题就出现了。最终目标是找到这些直方图中的峰值。

到目前为止,这就是我想出的。任何帮助将不胜感激。

非常感谢

%Make the number of pixels in the matrix divisible
Macropixel = 10; %determine the size of the macropixel
[rows,columns] = size(figureB); %determine dimentions of the matrix used in the calculations
MacropixRows = floor(rows/Macropixel); %determine how many macropixels are in a row of the original matrix
MacropixColumn = floor(columns/Macropixel); %determine how many macropixels are in a column of the original matrix

%define new dim for the matrix
rows = MacropixRows * Macropixel;
columns = MacropixColumn * Macropixel;
NewfigureB = figureB(1:rows,1:columns); %divisible by the size of the macropixels created

%select area 
NewfigureB = NewfigureB(1230:1349,2100:2269);

%create luminescence mask
Lmin=50;
hmax=80;
mask=false(size(NewfigureB));
mask(NewfigureB <Lmin)=true;
mask=mask & (NewfigureB<hmax);

%Apply mask
NewfigureB=NewfigureB(mask);


    for jj = 1:Macropixel:120
        for ii =1:Macropixel:170 
        histogram( NewfigureB(jj:jj+Macropixel-1, ii:ii+Macropixel-1))
        end
    end'''


【问题讨论】:

  • 请添加原始图片的链接。
  • @Hoki 我用这个作为案例研究:google.com/…:

标签: matlab image-processing histogram


【解决方案1】:

您发布的代码有太多问题。

我尽力纠正它。
我修改了一些参数来实现我使用的示例图像。
我找不到你的示例图片,所以我使用了following

这是一个更正的代码(请阅读 cmets):

I = imread('Nikon-D810-Image-Sample-7.jpg');

figureB = I(:,:,3);

%Make the number of pixels in the matrix divisible
Macropixel = 10; %determine the size of the macropixel
[rows,columns] = size(figureB); %determine dimentions of the matrix used in the calculations
MacropixRows = floor(rows/Macropixel); %determine how many macropixels are in a row of the original matrix
MacropixColumn = floor(columns/Macropixel); %determine how many macropixels are in a column of the original matrix

%define new dim for the matrix
rows = MacropixRows * Macropixel;
columns = MacropixColumn * Macropixel;
NewfigureB = figureB(1:rows,1:columns); %divisible by the size of the macropixels created

%select area 
NewfigureB = NewfigureB(1230:1349,2100:2269);

%create luminescence mask
Lmin=90;%50; %Change to 90 for testing
hmax=200;%80; %Change to 200 for testing
mask=false(size(NewfigureB));
mask(NewfigureB > Lmin)=true; %I think it should be > Lmin.   %mask(NewfigureB <Lmin)=true;
mask=mask & (NewfigureB<hmax);

%This is not the right way to apply a mask, because the result is a vector (not a matrix).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Apply mask
%NewfigureB=NewfigureB(mask);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%Assuming there are no zeros in the image, you can set masked elements to zero:  
NewfigureB(~mask) = 0;



for jj = 1:Macropixel:120
    for ii =1:Macropixel:170

        %Copy NewfigureB(jj:jj+Macropixel-1, ii:ii+Macropixel-1) into temporary matrix MB:
        MB = NewfigureB(jj:jj+Macropixel-1, ii:ii+Macropixel-1);

        %Remove the zeros from MB (zeros are masked elements).
        %The result is a vector (not a matrix).
        MB = MB(MB ~= 0);

        %histogram( NewfigureB(jj:jj+Macropixel-1, ii:ii+Macropixel-1))
        figure; %Open new figure for each histogram. (I don't know if it's a good idea).
        histogram(MB); %Plot the histogram of vector MB.
    end
end

这可能与意图不完全相符。
我希望它能给你一个领导......

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多