フィルターのクリア

Imwrite within a function

2 ビュー (過去 30 日間)
cjb b
cjb b 2013 年 6 月 26 日
I know there is a simple answer to this but I can't find it and I am on a tight deadline.
I am writing a function where I input an image, modify it, and then save it with a very similar name using imwrite.
For example, I want to put the image 'IA2.bmp' through my MaskFilter function.
img = imread(image);
rgbImage = img;
redBand = rgbImage(:,:, 1);
greenBand = rgbImage(:,:, 2);
blueBand = rgbImage(:,:, 3);
redthreshold = 25;
greenThreshold = 20;
blueThreshold = 25;
redMask = (redBand > redthreshold);
greenMask = (greenBand > greenThreshold);
blueMask =1- (blueBand < blueThreshold);
redObjectsMask = uint8(redMask & blueMask);
maskedrgbImage = uint8(zeros(size(redObjectsMask)));
maskedrgbImage(:,:,1) = rgbImage(:,:,1) .* redObjectsMask;
maskedrgbImage(:,:,2) = rgbImage(:,:,2);
maskedrgbImage(:,:,3) = rgbImage(:,:,3) .* redObjectsMask;
Now I want to save my modified image as 'IA2_MaskFiltered.tiff' (I have added the _MaskFiltered and changed it from a BMP to a Tiff).
I have tried numerous variations of imwrite but I can't get it to save as the modified name. Any suggestions?
Thanks for your help.

採用された回答

Image Analyst
Image Analyst 2013 年 6 月 26 日
For some reason you initialized maskedrgbImage to a single color channel. Not sure if that would cause a problem, or even what problem you observed (but didn't share) but I think this untested code should work:
maskedrgbImage = zeros(size(rgbImage), 'uint8');
maskedrgbImage(:,:,1) = rgbImage(:,:,1) .* redObjectsMask;
maskedrgbImage(:,:,2) = rgbImage(:,:,2);
maskedrgbImage(:,:,3) = rgbImage(:,:,3) .* redObjectsMask;
baseFileName = 'IA2_MaskFiltered.tiff';
yourFolder = 'D:\'; % or whatever...
fullFileName = fullfile(yourFolder, baseFileName);
imwrite(maskedrgbImage, fullFileName);
Make sure that maskedrgbImage is still a uint8 or uint16 image when you call imwrite().

その他の回答 (1 件)

Nitin
Nitin 2013 年 6 月 26 日
one of the many solutions:
temp = image.name(1:3); new_name = [temp,'_MaskFiltered.tiff'];
imwrite(modified_image,new_name);

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by