Creating an image filter

4 views (last 30 days)
Daniel
Daniel on 30 Sep 2011
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 Comment
Daniel
Daniel on 3 Oct 2011
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?

Sign in to comment.

Accepted Answer

Wayne King
Wayne King on 30 Sep 2011
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;

More Answers (1)

Wayne King
Wayne King on 3 Oct 2011
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 Comments
Image Analyst
Image Analyst on 4 Oct 2011
So can't you just do sumImage = sumImage + I ???
Walter Roberson
Walter Roberson on 4 Oct 2011
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

Sign in to comment.

Categories

Find more on Image Processing Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!