MATLAB如何在将数字保存为JPG时摆脱空白

时间:2015-10-23 20:18:56

标签: matlab border jpeg whitespace

我正在MATLAB中编写花朵识别代码 但每当我想保存一个数字 它以白色边框保存 - 边距 我怎么能删除它 并将其保存为原始图像的确切大小? 任何帮助将不胜感激

2 个答案:

答案 0 :(得分:1)

您可以使用 ;Validate the that a directory exists at that path. function ValidateFileDirectory(path : CString) return Boolean uses wUtil var testPath : CString ;Given the path to a directory,it will return True if that directory exists. ;-Test if the path is valid before you write a file. testPath = wUtil.FGETDIR(path) if testPath = path _Result = True else _Result = False Alert(kw_BadPath) ;! it will return false if you give it a path to a file, even if the file exists. endIf endFunc ;Validate that the file exists there. function ValidateFileExists(path : CString) return Boolean uses wUtil ;Given the path to a file, returns True if it finds the File. ;-test to make sure a file is there before you read, ;-test if a file was written. if wUtil.FGETNAME(path) <> '' _Result = True else Alert(kw_FileNotFound) _Result = False endIf endFunc function TestOpenFile(path : CString) return Int4 uses wUtil ;Returns 0 if it doesn't find a file, otherwise it returns a larger int4. _Result = wUtil.T_OPEN(path) wUtil.T_CLOSE(_Result) endFunc 来抓住轴而不是整个数字(仅凭getframe(gca)getframe就会发生这种情况)。然后将该帧转换为getframe(gcf)的图像。然后,您可以使用frame2im将该图像写入文件。

imwrite

答案 1 :(得分:0)

这可能会有所帮助:

figure('Color','none');
plot(1:10,1:10)
axis off
set(gca,'Color','none');
print ('-djpeg', 'no_background.jpg')