필터 지우기
필터 지우기

How can I save an image with its plotted centroids?

조회 수: 2 (최근 30일)
Nathan Costin
Nathan Costin 2016년 7월 5일
댓글: Image Analyst 2016년 7월 6일
I have found the center of some cells in an image and successfully plotted the centroids over these positions. However when I attempt to save the image only the original image is saved. Is there a way of saving the image with the centroids plotted? The code I am using is below and starts after I have converted the image 'I' to a binary image and done some processing to remove the noise:
baccenter = regionprops(imclean4, 'centroid');
centroids = cat(1, baccenter.Centroid);
measurements = regionprops(imclean4, 'BoundingBox', 'Area');
centroiddata = regionprops('table', imclean4, 'Centroid')
areadata = regionprops('table', imclean4, 'Area')
imshow(I)
hold on
plot(centroids(:,1),centroids(:,2), 'b*')
hold off
number_of_bacteria = numel(centroiddata)
locPath2 = '\\userfs\nac515\w2k\MATLAB\Tables and Pictures';
prompt2 = 'What would you like the image file to be called? ';
[~,locName] = fileparts(input(prompt2,'s'));
locFull2 = fullfile(locPath2,[locName,'.jpg']);
imwrite(I, locFull2)

답변 (2개)

Walter Roberson
Walter Roberson 2016년 7월 5일
You can use getframe to get a copy of what was rendered to the screen, and then imwrite() it to a file.
If you have Computer Vision Toolbox then you can instead not plot at all, and instead use insertShape to insert markers into the image array, and then imwrite() the image array.
  댓글 수: 5
Thorsten
Thorsten 2016년 7월 5일
You can use the following little convenience function to get things done:
function figwrite(filename)
if nargin == 0 % write to default file
filename = 'fig.png';
if exist('fig.png', 'file')
s = input(['Overwrite existing file ' filename '? Y/N >>'], 's');
if ~strcmpi(s, 'Y')
disp('No file written.')
return
end
end
end
F = getframe(gcf);
if isempty(F.colormap)
imwrite(F.cdata, filename);
else
imwrite(F.cdata, F.colormap, filename);
end
Nathan Costin
Nathan Costin 2016년 7월 6일
Thanks for your help, I was able to solve the issue using saveas :)

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


Image Analyst
Image Analyst 2016년 7월 5일
Or you can use export_fig
  댓글 수: 4
Nathan Costin
Nathan Costin 2016년 7월 6일
thank you very much for your help! I was able to solve the issue using saveas!
Image Analyst
Image Analyst 2016년 7월 6일
OK, fine if you don't care about the size. Like getframe, you don't get the same size as the original image. See the note for saveas in the help "Starting in R2016a, the size of saved figures match the size of the figure on the screen by default." So it saves the whole figure, not just the axes control only, and the size is different. But if you're okay with that, then have at it.

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

카테고리

Help CenterFile Exchange에서 Read, Write, and Modify Image에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by