sequence of image processing using the same background
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
Hi everybody I have a batch of images. For each image, I am using the same background image. How can I analyze all images using the same background image? When I read the one image, I will have to change the name of the background image as well, but I can not manage to change the background image name for each image that I need to analyze. I would also appreciate if you give me some info, suggestion regarding analyzing the batch of images in the same code?
Thanks!!!
採用された回答
Image Analyst
2018 年 5 月 22 日
See the FAQ for code samples: http://matlab.wikia.com/wiki/FAQ#How_can_I_process_a_sequence_of_files.3F
Inside the loop, create the new background image filename and read it in with imread(). Then read in the test image and use both of them to do your analysis.
11 件のコメント
engineer
2018 年 5 月 24 日
Thanks for the reply. I have been trying to sort it out, but I could not. I have images and I can import them in the matlab, but I don't have mat1.mat or file1.txt? What are those? Do I need to just read the images then, and delete the other codes? Inside the loop, do I need to read the background image (it is the same for other images that I wanna process the algorithm) as in reading batch of images?
Image Analyst
2018 年 5 月 24 日
Did you see both code samples? Or just the first one? What are your files named? Any pattern you want, or just analyze all of them with a particular extension?
engineer
2018 年 5 月 24 日
Yes I have seen. Let's say I have 10 images such as image1.png,image2.png....image10.png . and I have only one background image which is backgroundimage.png. How can I implement this into my code? Please tell me If I am not clear, as I am new in Matlab.
engineer
2018 年 5 月 24 日
all files are png.
read the background image before the loop
backgroundImage = imread(.........
fileList = dir(fullfile(yourFolder, '*.png'));
for k = 1 : length(fileList)
thisFileName = fullfile(fileList(k).folder, fileList(k).name);
thisImage = imread(thisFileName);
% Do something with thisImage and backgroundImage....
end
I tried to read the background image first but still, I could not make it work. I sent my initial code. What would you suggest based on the code I sent to read a batch of images by using just one background image.
Image Analyst
2018 年 5 月 25 日
You read in the very same file name for both the RGB image and the background image. Plus you did not have a loop over all images. Please answer these 3 questions:
- What is the name of the background image you want to use with every image?
- What is the file pattern for the RGB images you want to batch process? For example *.png or whatever...
- How do you want to use the background image with the RGB images? For example, divide them, subtract them, or what???
engineer
2018 年 5 月 25 日
編集済み: Image Analyst
2018 年 5 月 25 日
- Let's say the name of the background image is example_background.png which will be used with every image.
- PNG
- Divide them
Try this:
% Specify the folder where the files live.
myFolder = 'C:\Users\yourUserName\Documents\My Pictures';
% Check to make sure that folder actually exists. Warn user if it doesn't.
if ~isdir(myFolder)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder);
uiwait(warndlg(errorMessage));
return;
end
backgroundFullFileName = fullfile(myFolder, 'example_background.png');
if ~exist(backgroundFullFileName, 'file')
errorMessage = sprintf('Error: Background file does not exist:\n%s', backgroundFullFileName);
uiwait(errordlg(errorMessage));
else
backgroundImage = imread(backgroundFullFileName);
[rowsB, columnsB, numberOfColorChannelsB] = size(backgroundImage);
end
% Get a list of all files in the folder with the desired file name pattern.
filePattern = fullfile(myFolder, '*.PNG'); % Change to whatever pattern you need.
theFiles = dir(filePattern);
for k = 1 : length(theFiles)
baseFileName = theFiles(k).name;
fullFileName = fullfile(myFolder, baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
thisImage = imread(fullFileName);
imshow(thisImage); % Display image.
[rows, columns, numberOfColorChannels] = size(backgroundImage);
drawnow; % Force display to update immediately.
if rows ~= rowsB || columns ~= columnsB
thisImage = imresize(thisImage, size(backgroundImage));
end
correctedImage = double(thisImage) ./ double(backgroundImage);
imshow(correctedImage);
drawnow;
% Now do whatever you want with correctedImage, such as image analysis.
end
engineer
2018 年 5 月 30 日
Thank you very much. I was able to read all images including my background image. However, When I run the programme, correctedImage was full of white. I checked its pixel, it consist of just pixel 1, which is totaly white. What would be the problem? I could get a good background-corrected image.
Unfortunately you forgot to include your code, and I'm heading off to the airport in a couple of hours. Try this:
imshow(correctedImage, []);
It's possible that your background image is darker than your test images so the ratio is always greater than one so you need the empty brackets in imshow().
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Image Sequences and Batch Processing についてさらに検索
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)
