【问题标题】:Save Figure to new Image将图保存到新图像
【发布时间】:2017-06-05 06:25:27
【问题描述】:

我已经从图像中删除了线条,我想将它保存(图)到一个新图像中。

行被删除:

这是我的代码。

clc;              % Clear the command window.
close all;        % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures if you have the Image Processing Toolbox.
clear;            % Erase all existing variables. Or clearvars if you want.
workspace;        % Make sure the workspace panel is showing.
format short g;
format compact;
fontSize = 20;

grayImage = imread('tab1.png');
% Save this figure handle.
hFig1 = gcf;
% Get the dimensions of the image.  
% numberOfColorBands should be = 1.
[rows, columns, numberOfColorBands] = size(grayImage);
if numberOfColorBands > 1
    % It's not really gray scale like we expected - it's color.
    % Convert it to gray scale by taking only the green channel.
    grayImage = grayImage(:, :, 2); % Take green channel.
end

binaryImage = grayImage < 240;
binaryImage(: ,1: 20) = false;
imshow(grayImage, []);
hold on;
cc = bwconncomp(binaryImage);
% Measure the bounding box of all blobs.
measurements = regionprops(cc, 'BoundingBox');
fprintf('Found %d regions\n', cc.NumObjects);
numSkinnyRegions = 0;
bboxes=cat(1,measurements.BoundingBox);
for k = 1 : cc.NumObjects
    figure(hFig1); % Switch to figure 1.
    print(gcf,'Figuree','-dpng');
    thisBB = measurements(k).BoundingBox
    % Draw a box around the region in cyan.
    hRect = rectangle('Position', thisBB, 'EdgeColor', 'c', 'LineWidth', 1);
    aspectRatio(k) = thisBB(4)/thisBB(3);
    if (thisBB(4) <= 3 || thisBB(3) <= 3) && (aspectRatio(k) > 4 || aspectRatio(k) < 1/4)
        numSkinnyRegions = numSkinnyRegions + 1;
        % Save it to a cell array, just in case we want to use it after the loop is done.
        croppedImages{numSkinnyRegions} = imcrop(binaryImage, thisBB);      
        % Draw skinny regions in a different color
        delete(hRect); % Get rid of old one.
        hRect = rectangle('Position', thisBB);
        hRect.FaceColor = 'w';
        hRect.EdgeColor = 'w';
        hRect.LineWidth = 2;
   end
end

figure; imshow(grayImage) 

当我将图形保存到 png 文件中时,结果是图像包含一条黑线,与我在图中得到的不同。 saved image.

那么我的代码有什么问题?我是否将代码print(gcf,'Figuree','-dpng'); 放在了错误的行中?

【问题讨论】:

  • 在某种意义上删除行?您要删除原始图像中的这些线条吗?
  • 是的。有可能吗?
  • 您已经完成了删除,只需保存新图像?
  • 我不明白你的问题是什么。你能澄清一下吗?
  • 您已经删除了这些行。对 ?您无法保存图片吗?

标签: matlab image-processing


【解决方案1】:

好的,现在我有自己的答案了!只需使用来自mathworks file exchangeexport_fig。干杯!

【讨论】:

  • 好的,谢谢你的建议马克。我会尽快编辑它。
  • 为什么要从可能已经重新缩放/重新采样的图形中保存图像,从而降低任何未来处理的准确性,而不是只保存已经包含所有数据的 grayimage?跨度>
  • 因为我把过程保存在图中(hfig1 = gcf)而不是直接保存在图像中。
  • 现在这基本上是一个仅链接的答案,而不是真正喜欢的东西。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多