Matlab 将图形保存到新图像
我已经从图像中删除了行,我想将它保存到一个新图像中 删除以下行: 这是我的代码Matlab 将图形保存到新图像,matlab,image-processing,Matlab,Image Processing,我已经从图像中删除了行,我想将它保存到一个新图像中 删除以下行: 这是我的代码 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;
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)
clc;%清除命令窗口。
全部关闭;%关闭所有图形(imtool图形除外。)
imtool全部关闭;%如果您有图像处理工具箱,请关闭所有imtool图形。
清晰;%删除所有现有变量。或者clearvars,如果你愿意的话。
工作空间;%确保显示“工作区”面板。
格式缩写g;
格式紧凑;
fontSize=20;
grayImage=imread('tab1.png');
%保存此数字句柄。
hFig1=gcf;
%获取图像的尺寸。
%NumberOfColorBand应为=1。
[行、列、色带数]=大小(灰度图像);
如果numberOfColorBands>1
%它并不像我们预期的那样是灰色的,而是颜色。
%仅使用绿色通道将其转换为灰度。
灰度图像=灰度图像(:,:,2);%以绿色通道为例。
结束
二值图像=灰度图像<240;
二进制图像(:,1:20)=假;
imshow(灰度图像,[]);
等等
cc=BWConComp(二进制图像);
%测量所有水滴的边界框。
测量=区域属性(cc,“边界框”);
fprintf('找到%d个区域\n',cc.NumObjects);
numSkinnyRegions=0;
bboxes=类别(1,测量值。边界框);
对于k=1:cc.NumObjects
图(hFig1);%切换到图1。
印刷品(gcf、‘人物’、‘dpng’);
thisBB=测量值(k).边界框
%用青色在区域周围绘制一个框。
hRect=矩形('位置',thisb,'边缘颜色','c','线宽',1);
aspectRatio(k)=thisBB(4)/thisBB(3);
如果(b)(4)好的,现在我有了我自己的答案!只需使用导出图
from。干杯!删除意义上的线条?你想删除原始图像中的线条?是的。有可能吗?你已经删除了,只需保存新图像?我不明白你的问题是什么。你能澄清一下吗?你已经删除了线条。对吗无法保存图像?好的,谢谢你的建议标记。我很快会编辑它。为什么要保存可能已重新缩放/重新采样的图形的图像,从而降低任何未来处理的准确性,而不是只保存已包含所有数据的grayimage
?因为我在图(hfig1=gcf)中保存该过程不是直接在图像中。现在这基本上是一个链接唯一的答案,不是真正喜欢的东西。