2014-07-14 33 views
0

我使用的圖像,是其中我被使用imfinfo MATLAB中的細節如下:的通道數與Matlab VS opencv的

Filename: 'dog.jpg' 
        FileModDate: '25-Mar-2011 15:54:00' 
        FileSize: 8491 
         Format: 'jpg' 
       FormatVersion: '' 
         Width: 194 
         Height: 206 
        BitDepth: 24 
        ColorType: 'truecolor' 
       FormatSignature: '' 
       NumberOfSamples: 3 
       CodingMethod: 'Huffman' 
       CodingProcess: 'Sequential' 
         Comment: {} 
       NewSubFileType: 0 
       BitsPerSample: [8 8 8] 
    PhotometricInterpretation: 'RGB' 
      ImageDescription: [1x13 char] 
       StripOffsets: 154 
       SamplesPerPixel: 3 
       RowsPerStrip: 206 
       StripByteCounts: 119892 

它顯示了信道數= 3(與NumberOfSamples:3),但當我使用下面的代碼中找到OpenCV的信道的數量,我得到No. of channels = 1

Mat img = imread("dog.jpg", 0); 
printf("No. of Channels = %d\n", img.channels()); 

爲什麼會這樣?請解釋。

+3

imread( 「dog.jpg」,0); //最後的0 *強制* 8位灰度。嘗試1來強制執行bgr,或者對於'as is'執行-1。 – berak

+1

謝謝Berak。我是初學者,我剛剛開始與Opencv今天,你的幫助表示讚賞。再次感謝。 – Navdeep

+1

不客氣。只需保留一個指向[docs]的鏈接(http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html#imread);) – berak

回答

1

正如@berak所述,通過使用0作爲imread()的第二個參數,您將它作爲灰度圖像加載。嘗試通過傳遞負值<0來加載它,以便按原樣返回加載的圖像(帶有Alpha通道)或返回正值>0以返回3通道彩色圖像。

喜歡:

Mat img = imread("dog.jpg", -1); // <0 Return the loaded image as is 
          ^^ 
+0

謝謝。我嘗試過這個。有效。 – Navdeep