how to save the image as a RGB image???
조회 수: 19 (최근 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!