图像数据的Matlab hist函数 [英] Matlab hist function for image data

查看:345
本文介绍了图像数据的Matlab hist函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Matlab的新手,我想创建自己的函数来完成与imhist相同的工作(显示图像数据的直方图),但我是一个新手,我没有任何线索,我会开发这样的功能..
我开始做的东西,但它非常不完整。

pre $ function [output_args] = myhist(x)
%MYHIST这个函数的总结在这里
%详细的解释在这里

x = imread('flower.jpg');

imshow(x);

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

%图,imhist(x);
end

如果您能给我任何有用的提示,我将不胜感激。

解决方案

这是我尝试实现 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')

%#创建坐标轴并绘制灰度colorbar
hAx2 =轴('Position',get(hAx,'Position'),'HitTest','off');
图像(0:255,[0 1],repmat(linspace(0,1,256),[1 1 3]),'Parent',hAx2)
set(hAx2,'XLim',[ '255','YLim',[0 1],'YTick',[],'Box','on')

%#调整轴的大小以为colorbar腾出空间
set(hAx,'Units','像素')
p = get(hAx,'Position');
set(hAx,'Position',[p(1)p(2)+26 p(3)p(4)-26])
set(hAx,'Units','normalized' )

#底部的位置colorbar
set(hAx2,'Units','像素')
p = get(hAx2,'Position');
set(hAx2,'Position',[p(1:3)26])
set(hAx2,'Units','normalized')

%#link x - 两轴的限制
linkaxes([hAx; hAx2],'x')
set(gcf,'CurrentAxes',hAx)
end
 <$ c $  

让我们用示例图片对它进行测试: c> I = imread('coins.png');
figure(1),myimhist(I),title('myimhist')
figure(2),imhist(I),title('imhist')




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


I'm new to Matlab and I want to make my own function that makes the same job as imhist(Displays histogram of image data) but I am a total newbie to this and I don't have any clues how I'm going to develop such function.. I started making something but its very incomplete.

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

I would be very grateful if you could give me any helpful tips..

解决方案

Here is my attempt at implementing the IMHIST function. It does not handle all the cases that the official function does, but it should produce very similar results in most cases:

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

Let's test it with a sample image:

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

Note how IMHIST is apparently adjusting the y-limit so as to deal with the two different peaks in the histogram.

这篇关于图像数据的Matlab hist函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆