Hello,
I'm a beginner in MATLAB and image processing.
I encountered a problem while trying to use the batch processing and hope someone would be able to enlighten me. Thanks.
Following the example from MATLAB, I did these:
p = which('Picture1.tif');
filelist = dir([fileparts(p) filesep 'Picture*.tif']);
fileNames = {filelist.name}'
I = imread(fileNames{1});
imshow(I)
Because I wanted to select the region of interest,
BW = roipoly(I);
BW1 = not(BW);
N = roifill(I,BW1);
After I selected the ROI, I created a function in the editor:
function Segout = DetectLines(N)
[junk threshold] = edge(N, 'sobel');
fudgeFactor = .5;
BWs = edge(N, 'sobel', threshold*fudgeFactor);
se90 = strel('line', 3, 90);
se0 = strel('line', 3, 0);
BWsdil = imdilate(BWs, [se90 se0]);
BWdfill = imfill(BWsdil, 'holes');
BWnobord = imclearborder(BWdfill, 4);
seD = strel('diamond', 1);
BWfinal = imerode(BWnobord, seD);
BWfinal = imerode(BWfinal, seD);
BWoutline = bwperim(BWfinal);
Segout = N;
Segout(BWoutline) = 255;
end
Back to the command window, I typed;
Segout = DetectLines(N);
figure, imshow(Segout)
The figure that came out was what I expected.
The problem comes now when I try to loop over images. I'm not sure if I've done it correctly.
Following the example, I created another function in the editor;
function SegoutSequence = BatchProcessFiles(fileNames, fcn)
N = imread(fileNames{1});
[mrows, ncols] = size(N);
nImages = length(fileNames);
SegoutSequence = zeros(mrows, ncols, nImages, class(N));
parfor (k = 1:nImages)
N = imread(fileNames{k});
SegoutSequence(:,:,k) = fcn(N);
end
end
At the command window, I typed:
SegoutSequence = BatchProcessFiles(fileNames, @DetectLines);
implay(SegoutSequence)
However, the result was not what I wanted it to be. It was not the ROI that I wanted. Can anyone help me with this? Thank you very much.