How to get filename of input image in "Image Batch Processor" App?
Ältere Kommentare anzeigen
Hello. I'm trying to use the Image Batch Processor App to analyze a folder of images. My goal is to count the number of cells bodies, color the cell bodies green, and overlay these green dots onto the original image. I want the overlay figure to have the same file name and file format as the variable im (the current image file being read by the app), and saved in a different output folder.
My code is below. So far, I can get the function in the app to count the cells and generate the overlay image that I want. (Which is attached for reference. Note that the bottom of the image will be cropped out before processing). I can also assign a hardcoded name to the figure and save it to my output folder. However, I can't figure out how to get the name of the input image to assign to the figure window. Any help would be appreciated!
function results = myimfcn(im)
%segmentImage Segment image using auto-generated code from imageSegmenter App
% [BW,MASKEDIMAGE] = segmentImage(X) segments image X using auto-generated
% code from the imageSegmenter App. The final segmentation is returned in
% BW, and a masked image is returned in MASKEDIMAGE.
% Auto-generated by imageSegmenter app on 16-May-2017
%----------------------------------------------------
% IM - Input image.
% RESULTS - A scalar structure with the processing results.
close all;
% Threshold image - manual threshold
img=rgb2gray(im);
BW = img > 100;
% Close mask with disk
radius = 6;
decomposition = 0;
se = strel('disk', radius, decomposition);
BW = imclose(BW, se);
% Invert mask
BW = imcomplement(BW);
%Image Region Analyzer app filter code here
BW_filt = bwpropfilt(BW, 'Area', [150, 1000]);
%count cells
[~,n]=bwlabel(BW_filt);
%Change white in filtered image to green
blackImage = zeros(size(BW_filt));
rgbImage = cat(3, blackImage , BW_filt, blackImage);
%Overlay green mask onto original GRAYSCALE image
%[~,name,~] = fileparts(im); %get the name of the image file...HOW?
imshow(img);
hold on
green = cat(3, zeros(size(img)),ones(size(img)),zeros(size(img)));
h = imshow(green);
hold off;
% Use our filtered cells as the AlphaData for the solid green image.
set(h, 'AlphaData', BW_filt); %Not sure how to save this image in a batch
set(gcf, 'Name', 'Test1', 'NumberTitle','off'); %How to set file name of im variable, in place of 'Test1'?
figure=gcf;
title=figure.Name;
figuredir='C:\Users\bratka\Desktop\Output\';
saveas(gcf,strcat(figuredir,title),'png');
results.CellCount=n;
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Image Processing Toolbox finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!