I have a binary image of 100x150pixels. I want to do the loop function to read pixels of the binary image from bottom to top. Currently I'm doing side fill from bottom to top of image processiing. How can I write the variable of the row and column fr
You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Show older comments
Accepted Answer
Image Analyst
on 3 Apr 2015
Here's a start, this fills from the bottom of the edge image:
[rows, columns] = size(edgeImage);
% Output image
output = false(rows, columns); % Initialize
% Go across columns of image looking for last white pixel in the column.
for col = 1 : columns
lastRow = find(edgeImage, 1, 'last');
output(lastRow:end, col) = true;
end
imshow(output);
12 Comments
Then why did you accept this answer? When you accept an answer it tell other users that the issue has been resolved, and they will not bother to come and read this question. It also means that someone who helps later will not collect any points for helping you, even if they actually resolve your problem.
sorry for my misunderstanding about the accepted answer. I accept the answer as it helps me about the rows and columns.
Did I miss something? I think my code fills from the bottom edge to the bottom of the image, like the paper/website does and Nurul asked for, though it's just off the top of my head and I didn't test it.
can you please send to me the coding related to my analysis. Here is my emel : nurulnajmah_sabri@yahoo.com
Best regards,thank you
The code is above in my answer. Sorry but I don't have the time to donate to you to write an entire turnkey application for you, though it does look interesting. I was hoping that you could take the snippet I provided and finish the rest yourself. Or maybe you can contact the authors of that paper and offer to buy their code.
@Image Analyst: "Did I miss something?"... Yes, Nurul Najmah posted a comment that indicated that the question was not yet resolved... and then deleted it.
here the same problem that related to my problem. I am referring to this but using MATLAB.
Yes, but are you saying that the code I gave you doesn't work? It's the MATLAB version of what you say you want.
Nurul Najmah
on 6 Apr 2015
Edited: Image Analyst
on 7 Apr 2015
I am trying with this code;
% allocate space for new image
BW_fill = zeros(size(BW));
% loop over all bottom rows and columns
[~, columns]=size(BW);
row=1:100;
column=1:150;
BW_fill(start_rows,start_column)=new_pixel_value;
for start_row=150;
start_column=find(BW,'1',last');
if true;
new_pixelvalue=imfill(BW,'holes');
else new_pixelvalue=imfill(BW,'holes');
continue;
BW_fill(row-1,column-1)=new_pixel;
end
end
imshow(BW_fill);
but it doesn't work. The code that I got above works on my MATLAB. But for my mistake I didn't explain i want to find white pixel first. And fill the region row -- less than white pixel region with new_white. And fill the row++ with all black and proceed with the next column. Sorry sir for my poor English.

The code that I got from sir give me this output by comparing to the website. Can I know where is my mistake,sir?
You code looks nothing at all like the code I gave you. Attach BW so I can try my code on it.
We don't need to carry out this same discussion out over 5 threads. You didn't say what the problem was so I had to just go ahead and make a full blown demo for you with the binary image you posted in your other thread. Here it is:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
% Display binary image.
folder = fileparts(which('bwimg.png')); % Determine where demo folder is (works with all versions).
baseFileName = 'bwimg.png';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% File doesn't exist -- didn't find it there. Check the search path for it.
fullFileNameOnSearchPath = baseFileName; % No path this time.
if ~exist(fullFileNameOnSearchPath, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
% Display image.
subplot(1, 2, 1);
rgbImage = imread(fullFileName);
imshow(rgbImage, []);
title('Original Image', 'FontSize', fontSize);
axis on;
[rows, columns, numberOfColorChannels] = size(rgbImage);
if numberOfColorChannels > 1
BW = rgbImage(:,:,2) > 128;
else
BW = rgbImage > 128;
end
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Give a name to the title bar.
set(gcf, 'Name', 'Demo by ImageAnalyst', 'NumberTitle', 'Off')
% For some reason the first and last row of BW are all 1's.
% The poster saved it incorrectly or something.
% Anyway, zero out the first and last line.
BW(1, :) = false;
BW(end, :) = false;
% Go across columns of image looking for last white pixel in the column.
[rows, columns] = size(BW);
% Initialize last row
lastRow = rows * ones(1, columns);
% Output image
output = false(rows, columns); % Initialize
% Go across columns of image looking for last white pixel in the column.
for col = 1:columns
thisColumn = BW(:, col);
row = find(thisColumn, 1,'last');
if ~isempty(row)
lastRow(col) = find(thisColumn, 1,'last');
output(lastRow(col):end, col) = true;
end
end
subplot(1, 2, 2);
imshow(output, []);
title('Output Image', 'FontSize', fontSize);
axis on;

More Answers (0)
Categories
Find more on Image Transforms in Help Center and File Exchange
Products
Tags
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
