필터 지우기
필터 지우기

help with image processing code

조회 수: 3 (최근 30일)
aaa
aaa 2011년 7월 11일
Hi, i am new to matlab and need some help with this
i have used imread to read in a jpg image. however the workspace reads this as a 3 dimensional matrix, e.g. 150x100x3 uint8
how can i change this to a 2 dimensional matrix? i believe i have to use a gray scale image to accomplish this, but i cant seem to get it to work.
i have:
a = imread('image.jpg')
b = gray(a);
secondly, how can i read in a bunch of images into matlab for processing? i.e. i want to read in 1.jpg, 2.jpg, 3.jpg into the workspace. I know I need a for loop ,but i can't quite put the code together using the imread syntax.
for i = 1:5
a(i) = imread(xxxxx.jpg);
end
thank you

채택된 답변

Walter Roberson
Walter Roberson 2011년 7월 11일
b = rgb2gray(a);
To read a bunch of images, please see this FAQ
  댓글 수: 2
aaa
aaa 2011년 7월 12일
i just have another question regarding the FAQ you have. it refers to the following code to read a bunch of jpgs in to matlab.
jpegFiles = dir('*.jpg');
numfiles = length(jpegFiles);
mydata = cell(1,numfiles);
%%Processing a sequence of files (matlab doc)
for k = 1:numfiles
mydata(k) = imread(jpegFiles(k).name);
end
my problem is that i get the error "conversion to cell from uint8 is not possible" however, the imread function makes all images into uint8, and my guess is that the above code wants a "double" format.
However, i cannot do this pre-processing if i don't have the images loaded in the first place, so it seems to be counter-intuitive. What can I do to bypass this?
Walter Roberson
Walter Roberson 2011년 7월 12일
mydata{k} = imread(jpegFiles(k).name);
Notice the {k} instead of (k)

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

추가 답변 (1개)

aaa
aaa 2011년 7월 11일
thanks for the quick reply, i read through the faq and tried this but i get the following error
In an assignment A(:) = B, the number of elements in A and B must be the same.
Error in ==> test at 11 b(i) = sprintf('%d.jpg',k(i));
my code looks like
for i = 1:3
b(i) = sprintf('%d.jpg',i);
c(i) = imread(b(i));
end
thank you
  댓글 수: 1
Image Analyst
Image Analyst 2011년 7월 11일
Try b{i} instead of b(i).

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

카테고리

Help CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by