how to convert tiff image into gray image?

8 ビュー (過去 30 日間)
Mohammad
Mohammad 2014 年 9 月 20 日
コメント済み: Svetlana Zeveleva 2018 年 3 月 22 日
how to convert tiff image into gray image? I tried rgb2gray but it show me an error about "RGB must be a m x n x 3 array" my tiff image is (m x n x 4)
  1 件のコメント
Svetlana Zeveleva
Svetlana Zeveleva 2018 年 3 月 22 日
I'm having the same issue. But how did you find out the array size of your image?

サインインしてコメントする。

採用された回答

Guillaume
Guillaume 2014 年 9 月 20 日
Your image has a transparency channel in addition to the three colour channels. If you don't want to do anything with the transparency information, just discard it:
img(:,:,4) = [];
%proceed with rgb2gray
  4 件のコメント
Guillaume
Guillaume 2014 年 9 月 20 日
You can just save the grayscale image as tiff. If you wanted to convert it to rgb, it simply would be:
rgbimg = repmat(img, [1 1 3]);
And if you wanted a non-transparent transparency channel
rgbaimg = [repamt(img, [1 1 3]) zeros(size(img))];
There wouldn't be much point in either though.
Image Analyst
Image Analyst 2014 年 9 月 20 日
What do you mean "again"? Once it's in memory, it's just a 2D array of numbers. You can save the gray image out to a grayscale tiff image with imwrite:
filename = fullfile(folder, 'mygrayScaleTiff.tif');
imwrite(grayImage, filename);
If you want to save your RGB image, without the 4th channel which you removed and before you converted to grayscale and did other stuff, as an RGB image, you can (using Guillaume's code) save it with imwrite() like this:
filename = fullfile(folder, 'myRGBTiff.tif');
imwrite(img, filename);

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeConvert Image Type についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by