【问题标题】:Matlab hist function for image data图像数据的 Matlab hist 函数
【发布时间】:2011-11-16 02:27:52
【问题描述】:

我是 Matlab 的新手,我想创建自己的函数,与 imhist 做同样的工作(显示图像数据的直方图),但我完全是新手,我不知道我是怎么做的我要开发这样的功能.. 我开始制作一些东西,但它非常不完整。

function [ output_args ] = myhist( x )
%MYHIST Summary of this function goes here
%Detailed explanation goes here

x=imread('flower.jpg');

imshow(x);

[c,d]=hist(x(:),0:1:255);
figure,plot(d,c);
figure,plot(c,d);

%figure,imhist(x);
 end

如果您能给我任何有用的建议,我将不胜感激..

【问题讨论】:

    标签: image matlab function image-processing plot


    【解决方案1】:

    这是我实现IMHIST 函数的尝试。它不能处理官方函数处理的所有情况,但在大多数情况下应该会产生非常相似的结果:

    function myimhist(img)
        img = im2uint8(img);
    
        [count,bin] = hist(img(:), 0:255);
        stem(bin,count, 'Marker','none')
    
        hAx = gca;
        set(hAx, 'XLim',[0 255], 'XTickLabel',[], 'Box','on')
    
        %# create axes, and draw grayscale colorbar
        hAx2 = axes('Position',get(hAx,'Position'), 'HitTest','off');
        image(0:255, [0 1], repmat(linspace(0,1,256),[1 1 3]), 'Parent',hAx2)
        set(hAx2, 'XLim',[0 255], 'YLim',[0 1], 'YTick',[], 'Box','on')
    
        %# resize the axis to make room for the colorbar
        set(hAx, 'Units','pixels')
        p = get(hAx, 'Position');
        set(hAx, 'Position',[p(1) p(2)+26 p(3) p(4)-26])
        set(hAx, 'Units','normalized')
    
        %# position colorbar at bottom
        set(hAx2, 'Units','pixels')
        p = get(hAx2, 'Position');
        set(hAx2, 'Position',[p(1:3) 26])
        set(hAx2, 'Units','normalized')
    
        %# link x-limits of the two axes
        linkaxes([hAx;hAx2], 'x')
        set(gcf, 'CurrentAxes',hAx)
    end
    

    让我们用一个示例图像来测试一下:

    I = imread('coins.png');
    figure(1), myimhist(I), title('myimhist')
    figure(2), imhist(I), title('imhist')
    

    注意 IMHIST 显然是如何调整 y-limit 以处理直方图中的两个不同峰值。

    【讨论】:

      【解决方案2】:

      我不确定我是否理解您的目标。尝试替换

      figure,plot(d,c);
      

      figure,bar(d,c);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-01-20
        • 2014-04-21
        • 2017-03-12
        • 1970-01-01
        相关资源
        最近更新 更多