Creating an image filter

I'm currently trying to write a program that will read 80 images, all of the same size, and run each image through a filter/threshold before compiling them all into one single image.
The filter: The images are CT scans and in .jpg format. I am trying to create a high-pass filter or threshold that would assign all values below it(66) a 0 and anything above it 255.
I don't know where to start. I have some idea in my head but very limited knowledge on how to execute. Your help would be very much appreciated.

댓글 수: 1

Daniel
Daniel 2011년 10월 3일
Thank you Wayne. Your code works perfectly for single image files.
However, how would I write a loop for this program?
I know that using the: dir(*'jpg') command selects? the images you want to work with.
I changed the names of the images using matlab:
images=dir('*jpg');
names={images.name};
for File=1:numel(names)
newname=sprintf('04%d.jpg',File);
movefile(names{File},newname);
end
If I were to put the following code:
I = imread('cameraman.tif');
I(I<66) = 0;
I(I>66) = 255;
What would I replace the cameraman.tif with in order to have this run in a loop?
Also how would I be able to save these new images because I would like to add these images together once all of the images are filtered?

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

 채택된 답변

Wayne King
Wayne King 2011년 9월 30일

0 개 추천

Hi, if you just want to do that you can use logical indexing.
I = imread('cameraman.tif');
I(I<66) = 0;
I(I>66) = 255;

추가 답변 (1개)

Wayne King
Wayne King 2011년 10월 3일

0 개 추천

Hi Daniel, If you have
images = dir('*jpg');
names = {images.name};
Then you should be able to loop through on the cell array
for ii = 1:numel(names)
I = imread(names{ii});
I(I<66) = 0;
I(I>66) = 255;
...

댓글 수: 5

Daniel
Daniel 2011년 10월 3일
Wouldn't this output an image of only the last image in the directory?
Does this code automatically compile all the images into a single image? Because it seems like the image of I is the same as the image of the last image, after being run through the filter.
Image Analyst
Image Analyst 2011년 10월 4일
Well Daniel, you haven't defined exactly what you mean by "compile". So how are we supposed to answer you? Wayne gave you the "filter" part of your code but no one can help you anymore until you define "compile." Does it mean average together? Does it mean stack into a 3D image? Is it a maximum intensity projection? What the heck is it?
Daniel
Daniel 2011년 10월 4일
Thank you for your input.
When I say compile, I meant adding each image to the previous image. I would like to take the 80 files and "add" them together into one single image. I know I can filter 80 images separately and assign separate variables to save them, then use imadd to put them together; however, I would like to write a single loop that can do this.
Image Analyst
Image Analyst 2011년 10월 4일
So can't you just do sumImage = sumImage + I ???
Walter Roberson
Walter Roberson 2011년 10월 4일
You wouldn't want to use separate variables anyhow. See
http://matlab.wikia.com/wiki/FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F

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

카테고리

도움말 센터File Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

질문:

2011년 9월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by