how to find the matrix of 0's and 1's of the binary image in matlab
Show older comments
hello i need a code in matlab and C or C++ and java to upload a binary image and then find its pixel values and write it in the form of matrix of 0's and 1's. Then i need to check every pixel and few of it's neighbors.
Answers (1)
Image Analyst
on 26 May 2013
We can help you with MATLAB code, but usually not with C, C++, or Java. Where do you want to upload this binary image to? You forgot to tell us its destination. Is it some web site? Have you seen urlwrite?
urlwrite(URL,filename) readsWeb content at the specified URL and saves it tothe file specified by filename.
urlwrite(URL,filename,Name,Value)uses additional options specified by one or more Name,Value pairarguments.
Where do you want to write the image to? A file? The command window? A GUI? You forgot to say where you want to write it to.
What does "find its pixel values" and "check every pixel" mean to you? An image is an array of numbers so to "check it" you just give the subscripts, like pixelValue = imageArray(row, column) where row and column are numbers.
8 Comments
faraz.a
on 26 May 2013
Image Analyst
on 26 May 2013
Edited: Image Analyst
on 26 May 2013
"I can write algorithm and send you and how to send an image to you guys?" Post your image to http://snag.gy and your code here.
Here is a demo to extract and view bitplanes in a gray scale image:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
fontSize = 20;
% Read in a standard MATLAB gray scale demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
button = menu('Use which demo image?', 'CameraMan', 'Moon', 'Eight', 'Coins', 'Pout');
if button == 1
baseFileName = 'cameraman.tif';
elseif button == 2
baseFileName = 'moon.tif';
elseif button == 3
baseFileName = 'eight.tif';
elseif button == 4
baseFileName = 'coins.png';
else
baseFileName = 'pout.tif';
end
% Read in a standard MATLAB gray scale demo image.
folder = fullfile(matlabroot, '\toolbox\images\imdemos');
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
% Didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 1.
[rows columns numberOfColorBands] = size(grayImage);
% Display the original gray scale image.
subplot(2, 2, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Position', get(0,'Screensize'));
% Let's compute and display the histogram.
[pixelCount grayLevels] = imhist(grayImage);
subplot(2, 2, 2);
bar(pixelCount);
grid on;
title('Histogram of Original Grayscale Image', 'FontSize', fontSize);
xlim([0 grayLevels(end)]); % Scale x axis manually.
% Let's use this spot for the output image.
subplot(2, 3, 5);
for bp = 0 : 7
% Compute the bit plane image.
bitPlaneImage = bitand(grayImage, 2^bp);
% Display it as pure black and white (not gray scale).
imshow(bitPlaneImage, []);
caption = sprintf('You are now viewing bitplane %d.', bp);
title(caption, 'FontSize', fontSize);
% If it's not the last bit plane, ask them if they want to continue.
if bp ~= 7
message = sprintf('%s\nDo you want to continue', caption);
button = questdlg(message, 'Continue?', 'Yes', 'No', 'Yes');
drawnow; % Refresh screen to get rid of dialog box remnants.
if strcmpi(button, 'No')
break;
end
end
end
msgbox('Done with demo');
faraz.a
on 27 May 2013
faraz.a
on 27 May 2013
Image Analyst
on 27 May 2013
I believe you can get that by filtering the image with [1,1,0;1,0,0;0,0,0]
contextImage = imfilter(binaryImage, [1,1,0;1,0,0;0,0,0]);
The value of contextImage at each location will be the sum of the 1's in the upper left L-shape by the pixel.
faraz.a
on 28 May 2013
faraz.a
on 28 May 2013
Image Analyst
on 28 May 2013
I'm sorry but I don't have time to translate this into MATLAB for you.
Categories
Find more on Display 2-D Images in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!