Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 制作没有imhist的直方图_Matlab - Fatal编程技术网

Matlab 制作没有imhist的直方图

Matlab 制作没有imhist的直方图,matlab,Matlab,我试图在不使用imhist函数的情况下生成图像的直方图。我如何在不使用imhist的情况下复制它 originalImage = imread('hips.png'); imhist(originalImage); title('Histogram with Matlab'); 我知道我应该创建一个2D数组,并使用2 for循环来处理每个像素,但我不知道下一步该怎么做 谢谢。您可以使用hist函数获取每个频率值的像素数。然后您需要实现绘图部分 代码如下所示: function myimhist

我试图在不使用imhist函数的情况下生成图像的直方图。我如何在不使用imhist的情况下复制它

originalImage = imread('hips.png');
imhist(originalImage); title('Histogram with Matlab');
我知道我应该创建一个2D数组,并使用2 for循环来处理每个像素,但我不知道下一步该怎么做


谢谢。

您可以使用hist函数获取每个频率值的像素数。然后您需要实现绘图部分

代码如下所示:

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

可以使用hist函数获取每个频率值的像素数。然后您需要实现绘图部分

代码如下所示:

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

可以使用hist函数获取每个频率值的像素数。然后您需要实现绘图部分

代码如下所示:

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

可以使用hist函数获取每个频率值的像素数。然后您需要实现绘图部分

代码如下所示:

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