how do I get binary data image with the save button on the guide?

I am segmenting and saving images that have been segmented. The image was successfully saved with jpg type but I don't know how to save binary data from a segmented image.
is there a solution for this?
global frame
[name_file_save, path_save]=uiputfile ({'*.jpg','JPEG Image (*.jpg)';},'save citra');
if isequal(name_file_save,0) || isequal(path_save,0)
msgbox('Image is saved', 'Foto_Editor')
else
F=getframe(handles.axes2);
img=frame2im(F);
imwrite(img, fullfile(path_save,nama_file_save),'jpg');
end
axes(handles.axes2)

1 件のコメント

Walter Roberson
Walter Roberson 2020 年 5 月 17 日
Saving segmentation information as .jpg is not a good idea. .jpg blurs sharp lines, and segmentation information is all sharp lines.

サインインしてコメントする。

 採用された回答

Image Analyst
Image Analyst 2020 年 5 月 17 日
編集済み: Image Analyst 2020 年 5 月 17 日

1 投票

You don't need to use getframe(). That just saves a screenshot which will not even be the same size as the image you're hoping to save.
A segmented image is a binary / logical variable. You can save it with imwrite() if you cast to uint8. You might want to scale to 255 also.
% Make a uint8 image with values of 0 and 255 (so we can see it in the File Explorer thumbnail).
uint8Image = 255 * uint8(binaryImage); % binaryImage is your segmented image.
% Get base file name. Discard any extension they may have entered, like jpg.
[f, baseFileNameNoExt, ext] = fileparts(name_file_save);
% Construct full file name.
fullFileName = fullfile(path_save, [baseFileNameNoExt, '.png']); % NEVER use jpg for image analysis. Use PNG.
% Now do the actual save of the segmented image to disk as a PNG format image.
imwrite(uint8Image, fullFileName); % Save PNG image.

7 件のコメント

Walter Roberson
Walter Roberson 2020 年 5 月 17 日
You do not need to typecast or scale the logical() values: imwrite() will accept them directly, and will write as binary for BMP, PNG, and TIFF, and will take care of type conversion for the other file types.
olivio gusmao
olivio gusmao 2020 年 5 月 17 日
編集済み: Walter Roberson 2020 年 5 月 17 日
thank you .
how do we search for binary image data after segmenting without having to save the image in jpg or png ?
% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
citra = handles.image;
citraGray = rgb2gray(citra);
axes(handles.axes3);
imshow(citraGray);
% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axes (handles.axes1)
cla reset
set (gca,'XTick',[])
set (gca,'YTick',[])
axes (handles.axes2)
cla reset
set (gca,'XTick',[])
set (gca,'YTick',[])
axes (handles.axes3)
cla reset
set (gca,'XTick', [])
set (gca,'YTick', [])
%set (handles.pushbutton1,'Enable','off')
%set (handles.pushbutton5,'Enable','off')
%set (handles.btn_sobel,'Enable','off')
Image Analyst
Image Analyst 2020 年 5 月 17 日
Yes, you're right. Just to verify I made this code
binaryImage = logical(randi([0, 1], 20, 20));
imshow(binaryImage, 'InitialMagnification', 200);
% Save the logical image with no scaling or conversion.
imwrite(binaryImage, 'b.png'); % Save PNG image.
bRecalled = imread('b.png') % Will be of type logical and values of false and true.
% Make a uint8 image with values of 0 and 255.
uint8Image = 255 * uint8(binaryImage); % binaryImage is your segmented image.
% Now do the actual save of the segmented image to disk as a PNG format image.
imwrite(uint8Image, 'b255.png'); % Save PNG image.
b255Recalled = imread('b255.png') % Will be of type uint8 and values of 0 and 255.
and I verified that the thumbnails/icons look the same no matter if the range is 0-1 logical or 0&255 uint8. Also with the logical array, when it's recalled, it stays logical as you'd want. So there is no need to cast it to 255 uint8 like I did. Thanks for the clarification.
Walter Roberson
Walter Roberson 2020 年 5 月 17 日
how do we search for binary image data after segmenting without having to save the image in jpg or png ?
olivio gusmao
olivio gusmao 2020 年 5 月 20 日
how do we get binary data numbers only 0 and 1 from image data. what code should be added to that code?
Walter Roberson
Walter Roberson 2020 年 5 月 20 日
data_that_is_0_and_1s = double(binaryImage);
Image Analyst
Image Analyst 2020 年 5 月 20 日
binaryImage = imbinarize(grayScaleImage);

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeConvert Image Type についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by