您的位置:首页 > 其它

数字图像的基础知识和基础操作

2009-05-13 19:56 441 查看
图像相关术语:

像素

DPI

PPI

位,颜色

色图

图像类型

二值图像





>> bw=imread('12.png');
>>  figure(2)
>>  imshow(~bw)

figure(1)
>> imshow(bw)





>> info=imfinfo('12.png');
>> info

info =

                  Filename: '12.png'
               FileModDate: '13-May-2009 23:26:04'
                  FileSize: 9820
                    Format: 'png'
             FormatVersion: []
                     Width: 971
                    Height: 971
                  BitDepth: 1
                 ColorType: 'grayscale'
           FormatSignature: [137 80 78 71 13 10 26 10]
                  Colormap: []
                 Histogram: []
             InterlaceType: 'none'
              Transparency: 'none'
    SimpleTransparencyData: []
           BackgroundColor: []
           RenderingIntent: []
            Chromaticities: [1x8 double]
                     Gamma: 0.4545
               XResolution: 15748
               YResolution: 15748
            ResolutionUnit: 'meter'
                   XOffset: []
                   YOffset: []
                OffsetUnit: []
           SignificantBits: []
              ImageModTime: []
                     Title: []
                    Author: []
               Description: []
                 Copyright: []
              CreationTime: []
                  Software: []
                Disclaimer: []
                   Warning: []
                    Source: []
                   Comment: []
                 OtherText: []

RGB图像

又称真彩图像

实例:

>> info=imfinfo('13.jpg');
>> info

info =

           Filename: '13.jpg'
        FileModDate: '14-May-2009 00:03:44'
           FileSize: 151529
             Format: 'jpg'
      FormatVersion: ''
              Width: 1024
             Height: 724
           BitDepth: 24
          ColorType: 'truecolor'
    FormatSignature: ''
    NumberOfSamples: 3
       CodingMethod: 'Huffman'
      CodingProcess: 'Sequential'
            Comment: {}

>> rgb=imread('13.jpg');
>> imshow(rgb);

>> rgb(12,9,:)

ans(:,:,1) =

  206

ans(:,:,2) =

  132

ans(:,:,3) =

    9

>>





info=imfinfo('13.jpg')

将出现如下信息: 选择部分信息:

105   91   77   82   99  117  118  110  124  114   98
  100   77   63   80  106  120  114  105  131  123  112

  Columns 980 through 990

   24   24   24   24   24   24   24   24   24   24   24
   24   24   24   24   24   24   24   24   24   24   24
   24   24   24   24   24   24   24   24   24   24   24
   24   24   24   24   24   24   24   24   24   24   24
   24   24   24   24   24   24   24   24   24   24   24
   24   24   24   24   24   24   24   24   24   24   24

 

 

114  117  121  124  124  106  106  109  115  120  118
  103  107  113  117  118  117  112  108  109  113  115
   83   81   86   99  112  106  114  118  113  107  107
   77   72   74   83   90   90   99  107  108  108  110
   87   81   79   77   76   71   81   92  101  108  114
  105  100   93   83   76   63   71   83   95  108  117

  Columns 991 through 1001

   24   24   24   24   24   24   24   24   24   24   24
   24   24   24   24   24   24   24   24   24   24   24
   24   24   24   24   24   24   24   24   24   24   24
   24   24   24   24   24   24   24   24   24   24   24
   24   24   24   24   24   24   24   24   24   24   24
   24   24   24   24   24   24   24   24   24   24   24

 

112  107  110  124  109   85   72   55   62   98  109
110  113  110  114  117  111   98   85   77   75   80
112  112  114  114  114  113  107   98   89   82   75
114  110  118  114  112  115  118  114  103   92   76
116  110  119  114  112  117  124  122  111   99   84

Columns 1002 through 1012

  24   24   24   24   24   24   24   24   24   24   24
  24   24   24   24   24   24   24   24   24   24   24
  24   24   24   24   24   24   24   24   24   24   24
  24   24   24   24   24   24   24   24   24   24   24

116  116  117  119  114  114  115  114  109   96   79
116  116  117  119  115  114  115  114  109   95   78
116  116  117  119  116  115  116  114  109   95   77
116  116  117  119  118  116  116  114  109   94   76

Column 1024

  24
  24
  24
  24

>>i=rgh2gray(rgb)  把

>> imshow(i);





 

真彩图像分解:













x=imadd(rgb(:,:,1),rgb(:,:,2))

>> z=imadd(x,rgb(:,:,3));
>> imshow(z);
>> imshow(x);

实验证明:这样无法复原原来图片;

 

灰度图像

灰度图像是每个像素只有一个采样颜色的图像。这类图像通常显示为从最暗黑色到最亮的白色的灰度,尽管理论上这个采样可以任何颜色的不同深浅,甚至可以是不同亮度上的不同颜色。

灰度图像与黑白图像不同,在计算机图像领域中黑白图像只有黑色白色两种颜色;灰度图像在黑色与白色之间还有许多级的颜色深度。但是,在数字图像领域之外,“黑白图像”也表示“灰度图像”,例如灰度的照片通常叫做“黑白照片”。在一些关于数字图像的文章中单色图像等同于灰度图像,在另外一些文章中又等同于黑白图像。

灰度图像经常是在单个电磁波频谱如可见光内测量每个像素的亮度得到的。

用于显示的灰度图像通常用每个采样像素 8 位的非线性尺度来保存,这样可以有 256 级灰度。这种精度刚刚能够避免可见的条带失真,并且非常易于编程。在医学图像遥感图像这些技术应用中经常采用更多的级数以充分利用每个采样 10 或 12 位的传感器精度,并且避免计算时的近似误差。在这样的应用领域每个采样 16 位即 65536 级得到流行。

接下来的一些实验里头,将用一些例子来分析这两者的不同

>> j=imread('5.jpg');
>> subplot(121);
>> imshow(j)
>> subplot(122);
>> imshow(j,[100,200]);
>> figure ;

>> subplot(122);
>>  imshow(j,20);







索引图像

http://topic.csdn.net/u/20070505/16/3399cca4-4499-4438-8a7c-b2722141ba8f.html

 

图像格式

bmp

jpg

png

tif

gif

 

图像查询:

info=imfinfo('6.bmp')

info =

              Filename: '6.bmp'
           FileModDate: '13-May-2009 15:26:56'
              FileSize: 786486
                Format: 'bmp'
         FormatVersion: [1x33 char]
                 Width: 512
                Height: 512
              BitDepth: 24
             ColorType: 'truecolor'
       FormatSignature: 'BM'
    NumColormapEntries: 0
              Colormap: []
               RedMask: []
             GreenMask: []
              BlueMask: []
       ImageDataOffset: 54
      BitmapHeaderSize: 40
             NumPlanes: 1
       CompressionType: 'none'
            BitmapSize: 786432
        HorzResolution: 0
        VertResolution: 0
         NumColorsUsed: 0
    NumImportantColors: 0

 

6.bmp





 

 

图像类型的转换和判断;为什么要进行转换?因为很多图像处理工作对图像类型是有特定的要求的,比如对一幅索引图像首先要将它转化为真彩图像,否则,直接滤波是没有效果的.

info=imfinfo('15.jpg')
info

info =

           Filename: '15.jpg'
        FileModDate: '14-May-2009 12:33:14'
           FileSize: 35696
             Format: 'jpg'
      FormatVersion: ''
              Width: 700
             Height: 525
           BitDepth: 24
          ColorType: 'truecolor'
    FormatSignature: ''
    NumberOfSamples: 3
       CodingMethod: 'Huffman'
      CodingProcess: 'Sequential'
            Comment: {}

[x,map]=imread('15.jpg');
>> Image_Type_YN1=isind(x);
Warning: isind is obsolete and may be removed in the future.
See product release notes for more information.
> In isind at 32
>> disp(Image_Type_YN1)
     0

[x,map]=rgb2ind(x,0.5);
>> Image_Type_YN2=isind(x);
Warning: isind is obsolete and may be removed in the future.
See product release notes for more information.
> In isind at 32
>> Image_Type_YN2

Image_Type_YN2 =

     1

 





 

imwrite(x,map,'15_0.jpg','jpg');

figure;imshow('15_0.jpg')

>> info= imfinfo('15_0.jpg')

info =

           Filename: '15_0.jpg'
        FileModDate: '14-May-2009 13:03:42'
           FileSize: 156287
             Format: 'jpg'
      FormatVersion: ''
              Width: 700
             Height: 525
           BitDepth: 24
         ColorType: 'truecolor'
    FormatSignature: ''
    NumberOfSamples: 3
       CodingMethod: 'Huffman'
      CodingProcess: 'Sequential'
            Comment: {}  虽然是真彩,但是图像发生改变        先前的 15_0.jpg





>>  imwrite(x,'15_0.jpg','jpg');
>> info= imfinfo('15_0.jpg')

info =

           Filename: '15_0.jpg'
        FileModDate: '14-May-2009 13:07:32'
           FileSize: 10196
             Format: 'jpg'
      FormatVersion: ''
              Width: 700
             Height: 525
           BitDepth: 8
          ColorType: 'grayscale'
    FormatSignature: ''
    NumberOfSamples: 1
       CodingMethod: 'Huffman'
      CodingProcess: 'Sequential'
            Comment: {}

事实证实,在imwrite中,参数设定不当,无法保存转换后的图像类型

以下可以验证:

第二次 imwrite后生成的  15_0.jpg





>> i=imread(('15_0.jpg');
??? i=imread(('15_0.jpg');
                         |
Error: Expression or statement is incorrect--possibly unbalanced (, {, or [.

>>  i=imread('15_0.jpg');
>> t=isgray(i);
Warning: isgray is obsolete and may be removed in the future.
See product release notes for more information.
> In isgray at 27
>> t

t =

     1

>> y=isrgb(i);
Warning: isrgb is obsolete and may be removed in the future.
See product release notes for more information.
> In isrgb at 29
>> y

y =

     0

>>

另一个实验:

rgb=imread('17.bmp');

imshow(rgb);

[x1_no_dither,map]=rgb2ind(rgb,8,'nodither');

[x1_dither,map]=rgb2ind(rgb,8,'dither');

figure ,imshow(x1_no_dither,map);

figure ,imshow(x1_dither,map);

[rgb,map]=imread('17.bmp');

x2=rgb2gray(rgb);

newmap=rgb2gray(map);

figure,imshow(rgb,map);

figure,imshow(rgb,newmap);

figure ,imhsow(x2);

figure,imhsow(x2,newmap);









 





出错了地方,原因在于这里

>> newmap=rgb2gray(map);
??? Error using ==> rgb2gray>parse_inputs
MAP must be a m x 3 array.

Error in ==> rgb2gray at 35
X = parse_inputs(varargin{:});

>> info=imfinfo('17.bmp');
>> info

Width: 450
   Height: 338
BitDepth: 24  这是24位的图像宽度.
ColorType: 'truecolor'

                                                                                                            解决帮法是,位的转换,把24位图像转换位16位的图像,

 

 

先换一幅8位的gif图像:

>>  info=imfinfo('canoe.gif');
>> info

info =

           Filename: 'canoe.gif'
        FileModDate: '14-May-2009 13:56:38'
           FileSize: 241368
             Format: 'GIF'
      FormatVersion: '89a'
              Width: 764
             Height: 555
           BitDepth: 8
          ColorType: 'indexed'
    FormatSignature: 'GIF89a'
    BackgroundColor: 0
        AspectRatio: 0
         ColorTable: [256x3 double]
         Interlaced: 'yes'

由于它是indexed图像,所以还需转换成真彩图像,

灰度图像转化位索引图像,8比特

>> i=imread('5.jpg');
subplot(121);
  imshow(i);
  title('原灰度图像')
  subplot (122);
  [x,map]=gray2ind(i,6);
  imshow(x,map);
  title('转换后的图像')





 

>> bw=dither(i);
>> imshow(bw);
>>  title('转换后的二值图像')

 

 





 

>> [x,map]=imread('apple.jpg');
>> newmap=rgb2gray(map);
??? Error using ==> rgb2gray>parse_inputs
MAP must be a m x 3 array.

Error in ==> rgb2gray at 35
X = parse_inputs(varargin{:});

>>

这个错误:

Error using ==> rgb2gray>parse_inputs MAP must be a m x 3 array.

 

>> figure(1),imshow(x);
>> J=rgb2gray(x);
>> figure(2),imshow(J);
>>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: