简体   繁体   中英

using imwrite on a labeled image on matlab

I have an image that is result of labeling and applying boundaries. Each object is labeled with a number, then its boundary is defined.

图片要保存

The code I used is the following:

% bwboundaries() returns a cell array, where each cell contains the 
% row/column coordinates for an object in the image.
% Plot the borders of all the coins on the original grayscale image 
% using the coordinates returned by bwboundaries.

figure(2);
imshow(bwImage);
[r, c, p] = size(bwImage);
hold on
title('Outlines, from bwboundaries()', 'FontSize', fontSize); 
axis image;
% Make sure image is not artificially stretched because of 
% screen's aspect ratio.
hold on;
boundaries = bwboundaries(bw5);
numberOfBoundaries = size(boundaries, 1);
for k = 1 : numberOfBoundaries
thisBoundary = boundaries{k};
plot(thisBoundary(:,2), thisBoundary(:,1), 'g', 'LineWidth', 2);
end
hold off;

Now, I want to save the grayscale image AND the boundaries+labels applied above them in a variable, so that I can then do the following:

imwrite(A,'contours.jpg');

and save the image to do image post processing with GUI. It seemed really easy but every time I try it saves only the labels or only the boundaries on the grayscale image. I need both of them, as in the image I uploaded above. Thanks.

EDIT: As an alternative I could directly upload the image in a GUI interface but still, the problem of saving the correct image in a variable still remains.

You can use export_fig or saveas .

You can find many examples on the links, but the simplest command you can try is:

saveas(gcf,'filename.png')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM