保存直方圖

% --------------------------------------------------------------------
function SaveHist_Callback(hObject, eventdata, handles)

% hObject    handle to SaveHist (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% 直方圖對比
if isequal(handles.Img1, 0)
    msgbox('請載入圖像!', '提示信息');
    return;
end
if isequal(handles.Img2, 0)
    msgbox('請進(jìn)行去霧處理!', '提示信息');
    return;
end
figure('Name', '直方圖對比', 'NumberTitle', 'Off', ...
    'Units', 'Normalized', 'Position', [0.1 0.1 0.5 0.5]);
subplot(2, 2, 1); imshow(handles.Img1); title('原圖像', 'FontWeight', 'Bold');
subplot(2, 2, 2); imshow(handles.Img2); title('處理后的圖像', 'FontWeight', 'Bold');
Q = rgb2gray(handles.Img1);
W = rgb2gray(handles.Img2);
subplot(2, 2, 3); imhist(Q, 64); title('原灰度直方圖', 'FontWeight', 'Bold');
subplot(2, 2, 4); imhist(W, 64); title('處理后的灰度直方圖', 'FontWeight', 'Bold');

f = getframe(gcf);
f  = frame2im(f);
SaveHistImage(f);
function SaveHistImage(Img)
imagesPath = '.\\hist_results';
if ~exist(imagesPath, 'dir')
    mkdir(imagesPath);
end

[FileName,PathName,FilterIndex] = uiputfile({'*.jpg;*.tif;*.png;*.gif','All Image Files';...
          '*.*','All Files' },'保存直方圖',...
          '.\\hist_results\\result.jpg');
if isequal(FileName, 0) || isequal(PathName, 0)
    return;
end
fileStr = fullfile(PathName, FileName);
imwrite(Img, fileStr);
msgbox('處理結(jié)果保存成功!', '提示信息');
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容