how to save the image as a RGB image???
16 ビュー (過去 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!