how to save the image as a RGB image???
22 次查看(过去 30 天)
显示 更早的评论
This is the code for median filtering on RGB images. I wanted to save only the resorted image into a new folder. how do i do that?? can anyone help me out to save that image..
myFolder='E:\MRP\accuracy\class1';
m=input('Type the Number of Images to Process:');
for k = 1:m
jpgFilename = sprintf('%d.jpg', k);
fullFileName = fullfile(myFolder, jpgFilename);
rgbImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 3.
[rows columns numberOfColorBands] = size(rgbImage);
% Display the original color image.
figure,imshow(rgbImage);
title('Original color Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Position', get(0,'Screensize'));
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
% Display the individual red, green, and blue color channels.
figure,imshow(redChannel);
title('Red Channel', 'FontSize', fontSize);
figure,imshow(greenChannel);
title('Green Channel', 'FontSize', fontSize);
figure,imshow(blueChannel);
title('Blue Channel', 'FontSize', fontSize);
% Generate a noisy image. This has salt and pepper noise independently on
% each color channel so the noise may be colored.
noisyRGB = imnoise(rgbImage,'salt & pepper', 0.05);
figure,imshow(noisyRGB);
title('Image with Salt and Pepper Noise', 'FontSize', fontSize);
% Extract the individual red, green, and blue color channels.
redChannel = noisyRGB(:, :, 1);
greenChannel = noisyRGB(:, :, 2);
blueChannel = noisyRGB(:, :, 3);
% Display the noisy channel images.
figure,imshow(redChannel);
title('Noisy Red Channel', 'FontSize', fontSize);
figure,imshow(greenChannel);
title('Noisy Green Channel', 'FontSize', fontSize);
figure,imshow(blueChannel);
title('Noisy Blue Channel', 'FontSize', fontSize);
% Median Filter the channels:
redMF = medfilt2(redChannel, [3 3]);
greenMF = medfilt2(greenChannel, [3 3]);
blueMF = medfilt2(blueChannel, [3 3]);
% Find the noise in the red.
noiseImage = (redChannel == 0 | redChannel == 255);
% Get rid of the noise in the red by replacing with median.
noiseFreeRed = redChannel;
noiseFreeRed(noiseImage) = redMF(noiseImage);
% Find the noise in the green.
noiseImage = (greenChannel == 0 | greenChannel == 255);
% Get rid of the noise in the green by replacing with median.
noiseFreeGreen = greenChannel;
noiseFreeGreen(noiseImage) = greenMF(noiseImage);
% Find the noise in the blue.
noiseImage = (blueChannel == 0 | blueChannel == 255);
% Get rid of the noise in the blue by replacing with median.
noiseFreeBlue = blueChannel;
noiseFreeBlue(noiseImage) = blueMF(noiseImage);
% Reconstruct the noise free RGB image
rgbFixed = cat(3, noiseFreeRed, noiseFreeGreen, noiseFreeBlue);
figure,imshow(rgbFixed);
title('Restored Image', 'FontSize', fontSize);
end
0 个评论
采纳的回答
Image Analyst
2013-3-2
编辑:Image Analyst
2013-3-2
fullFileName = fullfile(yourFolder, 'fixed image.PNG');
imwrite(rgbFixed, fullFileName);
yourFolder is whatever folder you want to store your images in. It is a character string. For example
yourFolder = 'E:\MRP\accuracy\class2';
or
yourFolder = 'E:\MRP\accuracy\class1\output';
if ~exist(yourFolder, 'dir');
mkdir(yourFolder);
end
8 个评论
Image Analyst
2013-3-4
You haven't looked at the FAQ, http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F, yet, have you? It shows you how you can use sprintf() to create the base filename.
更多回答(2 个)
Youssef Khmou
2013-3-2
hi sudha,
finish your code by :
filename='E:\MRP\accuracy\class1\rgbFixed.jpg' % as jpg file
% or specifiy the directory you want 3
imwrite(rgbFixed,filename);
4 个评论
Walter Roberson
2013-3-2
Your posted code has
% Reconstruct the noise free RGB image
rgbFixed = cat(3, noiseFreeRed, noiseFreeGreen, noiseFreeBlue);
That is the code that defines the rgbFixed variable, which is the variable that holds the restored image.
That code is, though, far past line 14, which suggests you are now trying to write out something other than the restored image that you asked for assistance with. If you are going to try to do something other than what you asked for instructions on, you are going to need to learn how to adapt code examples instead of expecting that they will work exactly as given by the volunteers.
nkumar
2013-3-2
编辑:nkumar
2013-3-2
paste the following lines at starting of your code
pickind='jpg';
f1=fullfile('C:','framesnew');
if (exist(f1) == 0)
mkdir (f1);
end
paste the following line at last line before end statement
strtemp=strcat('C:\framesnew\',int2str(k),'.',pickind);
imwrite(rgbFixed,strtemp);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Processing Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!