tiff file data types

Hi, I am trying to write a function that takes a tif file as imageIn, then converts the data type into uint8 and gives out imageOut. the problem is that when I give a file which is not in logical data type format, it gives this error:
Matrix dimensions must agree. Error in Imfunction if class(image) == 'logical'
I dont understand how to fix the code. could someone help me figure it out? here is the code:
function imageOut = Imfunction(imageIn)
image = imread(imageIn);
if class(image) == 'logical'
image = uint8(image) .* uint8(255);
end
imwrite(image,'imageOut');
end

回答 (1 件)

Walter Roberson
Walter Roberson 2017 年 12 月 31 日

0 投票

Use islogical() instead of comparing the class.
If you must compare the class then use strcmp instead of == .
If you must use == then use R2016b or later and
if string(class(image)) == 'logical'

カテゴリ

ヘルプ センター および File ExchangeConvert Image Type についてさらに検索

タグ

質問済み:

K.G
2017 年 12 月 30 日

回答済み:

2017 年 12 月 31 日

Community Treasure Hunt

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

Start Hunting!

Translated by