Imwrite within a function
显示 更早的评论
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.
采纳的回答
更多回答(1 个)
Nitin
2013-6-26
0 个投票
one of the many solutions:
temp = image.name(1:3); new_name = [temp,'_MaskFiltered.tiff'];
imwrite(modified_image,new_name);
类别
在 帮助中心 和 File Exchange 中查找有关 Image Processing Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!