Image processing code Help
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
NEED help to use imread for 20 images together. This code can work on 1 image at a time i want to use this code for all 20 images at once and want to save all images in one new folder after processing .Please can anyone help me to modify this code.
RGB=imread('1.jpg');
% input 768*576 pixel uint8 type true color image.
R=RGB(:,:,1);
% red surface image extraction
G=RGB(:,:,2);
B=RGB(:,:,3);
figure;
imshow(RGB)
title('original image');
% create a new empty graphics window
% view images
figure,
imshow(R)
title('red face version');
figure,
imshow(G)
title('green face version');
figure,
imshow(B)
댓글 수: 3
Geoff Hayes
2020년 4월 16일
Anas - are all 20 files in the same folder? Which new image do you want to save to file - the extracted red, green or blue images? Where should the new files be saved to and what should their new names be?
Anas Bilal
2020년 4월 16일
all are images are in same golder. green red an dblue att want to save. names can img1 red, img2 green, img3 blue,....till 20. Images can save in "D:\First"
Anas Bilal
2020년 4월 16일
Image type is .jpg
채택된 답변
Ameer Hamza
2020년 4월 16일
편집: Ameer Hamza
2020년 4월 16일
0 개 추천
See my answer here related to batch processing of csv files: https://www.mathworks.com/matlabcentral/answers/509790-read-and-manipulate-multiple-csv-files
Here is a general structure of the code
files = dir('*.jpg'); % get name of all files with jpg extension
for i=1:numel(files) % run the for loop over all images
name = files(i).name; % get name of i-th image file
img = imread(name); % load the image
R=RGB(:,:,1);
% red surface image extraction
G=RGB(:,:,2);
B=RGB(:,:,3);
imwrite(R, ['img' num2str(i) ' red.jpg']);
imwrite(G, ['img' num2str(i) ' green.jpg']);
imwrite(B, ['img' num2str(i) ' blue.jpg']);
end
This link also provide helpful information: https://matlab.fandom.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F
댓글 수: 20
Anas Bilal
2020년 4월 16일
Not working
Can you please update my code accordingly.
all are images are in same golder. green red an dblue att want to save. names can img1 red, img2 green, img3 blue,....till 20. Images can save in "D:\First"
Image tyep .jpg
Ameer Hamza
2020년 4월 16일
Check the updated code. It will save each channel in a separate file. Since you are saving a single channel, the actual image will appear gray.
Anas Bilal
2020년 4월 16일
still not working
Ameer Hamza
2020년 4월 16일
What is the error?
Anas Bilal
2020년 4월 16일
Its working Thank you
Ameer Hamza
2020년 4월 16일
Glad to be of help.
Anas Bilal
2020년 4월 17일
I am facing one problem the code is working but it take just one picture and loop is not working. just one picture is preprocessed multiple times. it didn't pick the pictures in order just pick first picture and run it for multiple time.
Anas Bilal
2020년 4월 17일
eg picture name are
image001.png
image002.png
image003.png
.
...
.
.
.
.
.
.
image400.png
Ameer Hamza
2020년 4월 17일
Can you paste your code?
Anas Bilal
2020년 4월 17일
files = dir('*.ppm'); % get name of all files with jpg extension
for i=1:numel(files) % run the for loop over all images
name = files(i).name; % get name of i-th image file
img = imread(name); % load the image
R=RGB(:,:,1);
% red surface image extraction
G=RGB(:,:,2);
B=RGB(:,:,3);
imwrite(RGB, ['img' num2str(i) ' RGB.tif']);
imwrite(R, ['img' num2str(i) ' red.tif']);
imwrite(G, ['img' num2str(i) ' green.tif']);
imwrite(B, ['img' num2str(i) ' blue.tif']);
%histogram equivilzation of Green Channel
b=adapthisteq(G);
%Two times limited contrast adaptive direct equalization
ba=adapthisteq(b);
% adjusts contrast in grayscale images.
% increases
%figure;
imshow(ba)
title('enhanced contrast')
imwrite(ba, ['img' num2str(i) ' ba.tif']);
end
Anas Bilal
2020년 4월 17일
my images extension are .ppm and i want to save them as .tif
Ameer Hamza
2020년 4월 17일
I couldn't find an issue in the for loop. Can you add a breakpoint in your code and see if the loop is running once or 400 times for each image?
Anas Bilal
2020년 4월 17일
its run 400 time on a on 1 image and didn't use loop. just run for 1 image and then stop.
Ameer Hamza
2020년 4월 17일
What is the value of variable 'name' in each iteration? Does it get changed or remain same?
Anas Bilal
2020년 4월 17일
its run 400 time on a on 1 image and didn't use loop. just run for 1 image and then stop.
Image Analyst
2020년 4월 17일
Anas, it can't run 400 times on one image without using a loop, unless you had the cope copied 400 times, which I very much doubt. Most likely what happened is you didn't properly get the filename at the top of the loop. You didn't use the index and just got the same filename over and over again.
Anas Bilal
2020년 4월 17일
can you share your code.
Ameer Hamza
2020년 4월 17일
Anas, your code is correct. Can you show us the output after running these two lines?
files = dir('*.ppm');
numel(files)
Anas: I've corrected your code. This works. Just uncomment the imwrite() lines:
folder = pwd; % Whever you want...
filePattern = fullfile(folder, '*.ppm');
files = dir(filePattern); % get name of all files with jpg extension
if numel(files) == 0
warningMessage = sprintf('No files found in folder\n%s.\n', folder);
fprintf('%s\n', warningMessage);
beep;
uiwait(errordlg(warningMessage));
return;
end
numberOfImageFiles = length(files)
for k = 1 : numberOfImageFiles % run the for loop over all images
baseFileName = files(k).name; % get name of i-th image file
fullFileName = fullfile(folder, baseFileName);
fprintf('Reading in file %d of %d : %s\n', k, numberOfImageFiles, fullFileName);
img = imread(fullFileName); % load the image
subplot(1, 2, 1);
imshow(img);
caption = sprintf('Original Image :\n%s', baseFileName);
title(caption, 'FontSize', 15, 'Interpreter', 'none');
[rows, columns, numberOfColorChannels] = size(img);
if numberOfColorChannels == 3
R = img(:, :, 1); % Red channel image extraction
G = img(:, :, 2);
B = img(:, :, 3);
% Write out RGB image as TIFF format.
outputBaseFileName = sprintf('img %d RGB.tif', k);
outputFullFileName = fullfile(folder, outputBaseFileName);
fprintf(' Writing file %s\n', outputFullFileName);
% imwrite(R, outputFullFileName);
% Write out red image as TIFF format.
outputBaseFileName = sprintf('img %d red.tif', k);
outputFullFileName = fullfile(folder, outputBaseFileName);
fprintf(' Writing file %s\n', outputFullFileName);
% imwrite(R, outputFullFileName);
% Write out green image as TIFF format.
outputBaseFileName = sprintf('img %d green.tif', k);
outputFullFileName = fullfile(folder, outputBaseFileName);
fprintf(' Writing file %s\n', outputFullFileName);
% imwrite(R, outputFullFileName);
% Write out blue image as TIFF format.
outputBaseFileName = sprintf('img %d blue.tif', k);
outputFullFileName = fullfile(folder, outputBaseFileName);
fprintf(' Writing file %s\n', outputFullFileName);
% imwrite(R, outputFullFileName);
else
% img is already a gray scale image.
G = img;
end
% Histogram equivilzation of Green Channel
b=adapthisteq(G);
% Two times limited contrast adaptive direct equalization
ba=adapthisteq(b);
% adjusts contrast in grayscale images.
subplot(1, 2, 2);
imshow(ba)
title('Enhanced contrast', 'FontSize', 15, 'Interpreter', 'none');
outputBaseFileName = sprintf('img %d enhanced.tif', k);
outputFullFileName = fullfile(folder, outputBaseFileName);
fprintf(' Writing file %s\n', outputFullFileName);
% imwrite(ba, outputFullFileName);
drawnow;
pause(0.5);
end
Anas Bilal
2020년 4월 17일
Great work thank you very much .
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Convert Image Type에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
