I want to apply Marker-Controlled Watershed Segmentation on a folder containing .jpg images..So what modifications are required in the following code and I also want to store that results in a folder

4 ビュー (過去 30 日間)
path_directory='C:\Users\TIET\Desktop\tomato'; % 'Folder name' original_files=dir([path_directory '/*.jpg']); %Note on Image Format for k=1:length(original_files) filename=[path_directory '/' original_files(k).name]; image_ogi=imread(filename); gray=rgb2gray(image_ogi); destination='C:\Users\TIET\Desktop\tomato_output\im'; %Complete path of the folder imwrite(gray,[destination,num2str(k),'.jpg']); %Change the image formta as per desired image format end gmag = imgradient(gray); imshow(gmag,[]) title('Gradient Magnitude')
L = watershed(gmag); Lrgb = label2rgb(L); imshow(Lrgb) title('Watershed Transform of Gradient Magnitude')
se = strel('disk',20); Io = imopen(gray,se); imshow(Io) title('Opening')
Ie = imerode(gray,se); Iobr = imreconstruct(Ie,gray); imshow(Iobr) title('Opening-by-Reconstruction')
Ioc = imclose(Io,se); imshow(Ioc) title('Opening-Closing')
Iobrd = imdilate(Iobr,se); Iobrcbr = imreconstruct(imcomplement(Iobrd),imcomplement(Iobr)); Iobrcbr = imcomplement(Iobrcbr); imshow(Iobrcbr) title('Opening-Closing by Reconstruction')
fgm = imregionalmax(Iobrcbr); imshow(fgm) title('Regional Maxima of Opening-Closing by Reconstruction')
I2 = labeloverlay(gray,fgm); imshow(I2) title('Regional Maxima Superimposed on Original Image')
se2 = strel(ones(5,5)); fgm2 = imclose(fgm,se2); fgm3 = imerode(fgm2,se2);
fgm4 = bwareaopen(fgm3,20); I3 = labeloverlay(gray,fgm4); imshow(I3) title('Modified Regional Maxima Superimposed on Original Image')
bw = imbinarize(Iobrcbr); imshow(bw) title('Thresholded Opening-Closing by Reconstruction')
D = bwdist(bw); DL = watershed(D); bgm = DL == 0; imshow(bgm) title('Watershed Ridge Lines)') gmag2 = imimposemin(gmag, bgm | fgm4); L = watershed(gmag2);
labels = imdilate(L==0,ones(3,3)) + 2*bgm + 3*fgm4; I4 = labeloverlay(gray,labels); imshow(I4) title('Markers and Object Boundaries Superimposed on Original Image')
Lrgb = label2rgb(L,'jet','w','shuffle'); imshow(Lrgb) title('Colored Watershed Label Matrix')
figure imshow(gray) hold on himage = imshow(Lrgb); himage.AlphaData = 0.3; title('Colored Labels Superimposed Transparently on Original Image')

採用された回答

KALYAN ACHARJYA
KALYAN ACHARJYA 2018 年 9 月 15 日
編集済み: KALYAN ACHARJYA 2018 年 9 月 15 日
path_directory='tomato'; % 'Folder name'
original_files=dir([path_directory '/*.jpg']); %Note on Image Format
for k=1:length(original_files)
filename=[path_directory '/' original_files(k).name];
image_ogi=imread(filename);
gray=rgb2gray(image_ogi);
gmag=imgradient(gray);
L=watershed(gmag);
Lrgb=label2rgb(L);
se=strel('disk',20);
Io=imopen(gray,se);
Ie=imerode(gray,se);
Iobr=imreconstruct(Ie,gray);
Iobrd=imdilate(Iobr,se);
Iobrcbr=imreconstruct(imcomplement(Iobrd),imcomplement(Iobr));
Iobrcbr=imcomplement(Iobrcbr);
fgm=imregionalmax(Iobrcbr);
I2=labeloverlay(gray,fgm);
se2=strel(ones(5,5));
fgm2=imclose(fgm,se2);
fgm3=imerode(fgm2,se2);
fgm4=bwareaopen(fgm3,20);
I3=labeloverlay(gray,fgm4);
bw=imbinarize(Iobrcbr);
D=bwdist(bw);
DL=watershed(D);
bgm=DL==0;
gmag2=imimposemin(gmag,bgm | fgm4);
L=watershed(gmag2);
labels=imdilate(L==0,ones(3,3))+2*bgm+3*fgm4;
I4=labeloverlay(gray,labels);
Lrgb=label2rgb(L,'jet','w','shuffle');
himage=imshow(Lrgb);
himage.AlphaData=0.3;
title('Colored Labels Superimposed Transparently on Original Image')
destination='C:\Users\TIET\Desktop\tomato_output\im';
imwrite(himage,[destination,num2str(k),'.jpg']); %Change the image formta as per desired image format
end
  2 件のコメント
KALYAN ACHARJYA
KALYAN ACHARJYA 2018 年 9 月 15 日
編集済み: KALYAN ACHARJYA 2018 年 9 月 15 日
@ImageAnalyst Yes sir,Thanks I didn't check the code inside.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeImage Segmentation and Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by