What is code to convert an RGB image to binary image , and then save that image in form of matrix in notepad? one more question: code to convert binary matrix in notepad to Binary image format? Please reply fast
-
I have an image(PNG, JPEG, etc) in the RGB format. However, I would like to create a routine for loading into MATLAB saving it in a text file which can be viewing in a notepad.
-
Answer:
how can we convert random lines detected in m...
Muhammad Waqar at Quora Visit the source
Other answers
The following would be one of the alternatives to 's answer for saving the image, otherwise his method works well too. The resulting answer is logical, but has a double value which is the reason for the formatting in the text file. Writing a logical value into a text in ASCII format is not supported (http://www.mathworks.com/help/matlab/ref/save.html) . You can type the following in MATLAB: %Read the image im = imread('peppers.png'); %Conversion im = double(im2bw(im)); %Write to file save('peppers.txt','-ascii','im')
Lokesh Amarnath
Here is a matlab code that does it:- %Read the image im = imread('a.jpg'); %Convert it to bw im = im2bw(im); %Open file stream fid = fopen('abc.txt','w'); [row col] = size(i); for x=1:row for y=1:col fprintf(fid,'%d ',i(x,y)); end fprintf(fid,'\n'); end fclose(fid); Hint: Use your file names instead of 'a.jpg' and 'abc.txt' also 'a.jpg' should be in the same folder as this script. Update: This will work with other image formats too.
Anonymous
%%%%%code for rgb to binary image I = imread('imagename.jpg/png'); %read image level=0.5; % level value 1 (white) and 0 (black) BW = im2bw(I, level); %converts the truecolor image RGB to a binary image. imshow(I), figure, imshow(BW) %%%%%%%%%%% %%save as text file in form of matrix fid = fopen('myoutput.txt', 'w'); fprintf(fid, '%f', BW); fclose(fid);
Amit Singh
Related Q & A:
- How to find out if it is possible to contruct a binary matrix with given row and column sums?Best solution by Mathematics
- Where can I save the image?Best solution by Stack Overflow
- How to save an image in LocalStorage?Best solution by Stack Overflow
- What is an upright image and real image?Best solution by Yahoo! Answers
- How do you save an image from an email on yahoo?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.