필터 지우기
필터 지우기

Function with multiple inputs

조회 수: 2 (최근 30일)
Poreddy ajaykumar reddy
Poreddy ajaykumar reddy 2021년 9월 12일
답변: Prateek Rai 2021년 9월 14일
Hello everyone
I have a function with two inputs
function [output_image]=multiple(input_1,input_2)
assume
input_1=imread('image from input folder_1')
input_2=imread('image from input folder_2 ')
output_image=input_1+input_2 % assume this as preprocessing stage
%i need to stire all the images after prerocessig in folder
%i have 90 images in folder_1 and 90 images in folder_2 and this images
%should be read in sequence
%example like folder_1 : 1st image
% folder_2=first image
end
please help me to write a loop
  댓글 수: 3
Poreddy ajaykumar reddy
Poreddy ajaykumar reddy 2021년 9월 12일
@Walter Roberson they have different names and they are from different folders
extension is same
Walter Roberson
Walter Roberson 2021년 9월 12일
Okay, so given the name in one folder, how do you know which name in the other folder is the corresponding image ?

댓글을 달려면 로그인하십시오.

채택된 답변

Prateek Rai
Prateek Rai 2021년 9월 14일
To my understanding, you have 2 folders with same number of images and you want to preprocess the images and use the final output image. First of all you can make a hierarchy of files in the following way.
  • folder_1 contains 90 images
  • folder_2 contains 90 images
  • folder_3 (empty folder to save output image)
Now you can use imageDatastore function to read all images from folder_1 and folder_2.
imds1 = imageDatastore('folder_1');
imds2 = imageDatastore('folder_2');
Number of images in folder can be retrieved using:
l = length(imds1.Files);
Now you can run a loop from i=1 to length and read images from folder_1 and folder_2, make the required calculations and finally write the new preprocessed image in folder_3.
for i=1:1:l
% reading images one by one from folder_1 and folder_2
img1 = imread(imds1.Files{i});
img2 = imread(imds2.Files{i});
out_img = img1+img2; % preprocessing stage
% this is important to create a location where final image can be saved
% You can change '.jpg' with the file format your images have
output_loc = "folder_3\image" + num2str(i) + ".jpg";
% It will save the prepocessed image in the location specified by output_loc
imwrite(out_img,output_loc)
end
Here is a full working function for your problem:
imds1 = imageDatastore('folder_1');
imds2 = imageDatastore('folder_2');
l = length(imds1.Files);
for i=1:1:l
% reading images one by one from folder_1 and folder_2
img1 = imread(imds1.Files{i});
img2 = imread(imds2.Files{i});
out_img = img1+img2; % preprocessing stage
% this is important to create a location where final image can be saved
% You can change '.jpg' with the file format your images have
output_loc = "folder_3\image" + num2str(i) + ".jpg";
% It will save the prepocessed image in the location specified by output_loc
imwrite(out_img,output_loc)
end
You can refer to imageDatastore MathWorks documentation page to find more on Datastore for image data.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by