如何在matlab中保存/存储图像?

时间:2014-01-28 06:49:11

标签: matlab image-processing

参考mathworks“SimpleColorDetector”http://www.mathworks.com/matlabcentral/fileexchange/26420-simplecolordetection

中的示例

有人可以告诉我如何保存图像'redObjectsMask'吗?

我尝试用imwrite(redObjectsMask,'test.jpg');

保存它

但它被保存为黑色图像。 但是在imshow(redObjectsMask,[]);

它显示正确的图像。

以下是代码示例:

redMask = (redBand >= redThresholdLow) & (redBand <= redThresholdHigh);
greenMask = (greenBand >= greenThresholdLow) & (greenBand <= greenThresholdHigh);
blueMask = (blueBand >= blueThresholdLow) & (blueBand <= blueThresholdHigh);

redObjectsMask = uint8(redMask & greenMask & blueMask);
    subplot(3, 3, 4);
    imshow(redObjectsMask, []); % this shows the image I require to be saved
    imwrite(redObjectsMask,'test.jpg'); % this saves a blank image

1 个答案:

答案 0 :(得分:0)

使用空括号[]作为imshow的第二个参数,缩放显示的图像强度。您需要执行相同的操作来保存图像。

redObjectsMask = double( redObjectsMask ); % make sure you work with float type
redObjectsMask = ( redObjectsMask - min(redObjectsMask(:) ) ./ ( max(redObjectsMask(:)) - min( redObjectsMask(:)) );
imwrite( redObjectsMask, 'test.jpg');

如果redObjectsMask属于逻辑类型,您可以更轻松地解决它:

redObjectsMask = uint8( redObjectsMask ) * 255; % white is 255 and not 1
imwrite( redObjectsMask, 'test.jpg');