Azzera filtri
Azzera filtri

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

2 visualizzazioni (ultimi 30 giorni)

Risposta accettata

Image Analyst
Image Analyst il 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 Commenti
Image Analyst
Image Analyst il 19 Apr 2015
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;

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Image Processing Toolbox in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by