【问题标题】:local histograms - recomputing histograms for all parts of the image - Matlab局部直方图 - 重新计算图像所有部分的直方图 - Matlab
【发布时间】:2012-11-12 21:00:22
【问题描述】:

我已经有了这个:
function [h] = histImage (img)
nPix = numel(img);
h = accumarray( img (:)+1 , ones(nPix,1)/nPix, [256 1] , @sum,0)

此函数会将给定 img 的灰度直方图返回到 1X256 向量中

现在我想构建这个函数: 输入:img - 愤怒中的灰度图像矩阵 [0..255] windowSize - 一个 1x2 数组 [r c] 行和列。
输出: histArray 3d matrix for each i,j the 1D array histArray(i,j,:) 是大小为 WindowSize 的 img 的直方图,其左上角为 (i,j)

函数 [histArray] = localHistograms (img,windowSize)
histArray = zeros(windowSize(1),WindowSize(2),256);
对于 i = 1:windowSize(1)
    对于 j = 1:windowSize(2)
        histArray(i,j,:) = histImage(img( i:windowSize(1), j:windowSize(2) ))
    结尾
结尾
结尾

这是我到目前为止所拥有的,你能告诉我我的错误吗? 我如何检查我的错误?随便输入一些图片?

【问题讨论】:

  • 有什么问题吗?
  • 我认为我没有得到正确的价值观。我是图像处理的新手。检查我是否正确的最简单方法是什么?
  • 制作一个窗口大小的图像,以便您确切知道结果应该是什么。
  • 你使用 Photoshop 还是只使用矩阵/向量
  • 你只是把一个矩阵放在一起。您可以单独指定所有值,或使用 magic(3) 之类的东西来创建指定的 3x3 数组。

标签: image matlab image-processing


【解决方案1】:

好的,所以我的朋友帮我找出我的错误是工作和测试的代码:

function [ histArray  ] = localHistograms ( img,windowSize )
% Given an image returns a 3D array of histograms – 
% one histogram per window in image.
% Input:
%   img - a grayscale image in the range [0..255]
%   windowSize – a 1x2 array [r c]  defining the num rows and num cols 
%                of image windows.      
% Output:
%   histArray – an NxMx256 array.
%
% For every (i,j) the 1D array histArray(i,j,:) is the histogram
% of an image window of size windowSize whose top left corner 
% pixel is (i,j). Histograms of windows that exceed the boundary 
% of the of img are not included in histArray (thus N = number of 
% rows of img less the number of rows of window +1. 
% Similarly  M=size(img,2)-windowSize(2)+1 ).
%
% Method:   Scans the img pixel by pixel. For each scanned pixel,
% determines the histogram of the image window starting at the 
% pixel and extending  windowSize(1) rows and windowSize(2).

N = size(img,1) - windowSize(1) + 1;
M = size(img,2) - windowSize(2) + 1;
histArray = zeros(N ,M,256);

for i = 1:N
 for j = 1:M
   histArray(i,j,:) = histImage(img(i:i+windowSize(1)-1,j:j+windowSize(2)-1));
 end
end

end

【讨论】:

    猜你喜欢
    • 2014-03-12
    • 1970-01-01
    • 2014-04-05
    • 2013-12-03
    • 1970-01-01
    • 2021-06-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-12
    相关资源
    最近更新 更多