From: Sami Oueslati on
Thanks for accepting to help me,
Here's the program's code. Some variables are in French..I translated a big part of it in English. Hope it's clear in general
I put the original bitmap image to test http://drop.io/mqlwmho#
-------------------------------------------------------------------------------------------------------
clc;
close all;
clear all;

%----------------------read and show the image-----------------
I=input('Choose an image:');
I = imread(I);
I = rgb2gray(I);
I = medfilt2(I);
h = ones(3,3);
ImageGris = imerode(I,h);
subplot(3,2, 1);
imshow(ImageGris);
title('Image prétraitée');
axis on;

%----------------------Binarize Image---------------
ImageBinarisee = ImageGris > 85;
ImageBinarisee=~ImageBinarisee;
ImageBinarisee = bwareaopen(ImageBinarisee,30);
subplot(3,2, 2);
imshow(ImageBinarisee, []);
title('Image binarisée');
axis on;

%----------------------Vertical Bands---------------
[lign col Ncb] = size(ImageGris);
ImageBinarisee(1,:)=0;
ImageBinarisee(:,1)=0;
ImageBinarisee(:,size(ImageBinarisee,2))=0;
ImageBinarisee(size(ImageBinarisee,1),:)=0;
ImageBandes = uint8(127 * ones(lign, col));
ImageBandes(:, max(ImageBinarisee,[],1) > 0 ) = 255;
subplot(3,2, 3);
imshow(ImageBandes);
title('Bandes verticales');
axis on;

%----------------------Vertical Midlines------------
VProfil = (max(ImageBinarisee) == 1);
BandeBord = diff(VProfil);% localize start and end of band
BandeDebut = find(BandeBord == 1);% localize start of band
BandeFin = find(BandeBord == -1);% Localize end of band
LigneV = round((BandeDebut + BandeFin) / 2);
ImageBinarisee1 = ImageBandes; %
ImageBinarisee1(:, LigneV) = 0; % Draw midlines.

subplot(3,2, 4);
imshow(ImageBinarisee1, []);
title('Bandes verticales coupées au milieu');
axis on;

%--------------------Horizontal Bands--------------------------
ImageBandes1 = uint8(127 * ones(lign, col));
ImageBandes1(max(ImageBinarisee,[],2) > 0,:) = 255;
subplot(3,2, 5);
imshow(ImageBandes1);
title('Bandes horizontales');
axis on;

%--------------------Horizontal Midlines--------------------
HProfil = (max(ImageBinarisee,[],2) == 1);
HProfil=HProfil';
BandeBord1 = diff(HProfil,[],2);% Localiza start and end of bands
BandeDebut1 = find(BandeBord1 == 1);% localize start of band
BandeFin1 = find(BandeBord1 == -1);% Localize end of band
LigneH = round((BandeDebut1 + BandeFin1) / 2);
ImageBinarisee2 = ImageBandes1;
ImageBinarisee2(LigneH,:) = 0; % Draw midlines.

subplot(3,2, 6);
imshow(ImageBinarisee2, []);
title('Bandes horizontales coupées au milieu');
axis on;

%---------------Image with grid-----------------------------------
ImageGrille = ImageGris;
ImageGrille(:,LigneV) = 0; %tracer les lignes verticales
ImageGrille(LigneH,:) = 0; %tracer les lignes horizontales

figure, imshow(ImageGrille);
title('Image avec grille');
axis on;

%------------Grayscale values of center of each region------- %INCOMPLETE

for x = 1:LigneH:lign
for y = 1:LigneV:col
CaseGrille = ImageGris(x:LigneH,y:LigneV);
end

end
From: ImageAnalyst on
On May 8, 11:07 pm, "Sami Oueslati" <Samy...(a)yahoo.fr> wrote:
> Thanks for accepting to help me,
> Here's the program's code. Some variables are in French..I translated a big part of it in English. Hope it's clear in general
> I put the original bitmap image to test http://drop.io/mqlwmho#
> -------------------------------------------------------------------------------------------------------

Your original image does not have any black grille over it so how can
you find it?

Plus your original image seems to be overexposed.
I've been thinking that you have an image that you're starting with
that has black vertical lines and black horizontal lines over it, but
now you post an original image with no such lines.
Apparently the lines were drawn afterwards. If you drew them then you
know where you drew them.
Why don't you just forget about the grille (black lines), and explain
what you want to do with the original (no grille) image?
From: Sami Oueslati on
> Your original image does not have any black grille over it so how can
> you find it?
>
> Plus your original image seems to be overexposed.
> I've been thinking that you have an image that you're starting with
> that has black vertical lines and black horizontal lines over it, but
> now you post an original image with no such lines.
> Apparently the lines were drawn afterwards. If you drew them then you
> know where you drew them.
> Why don't you just forget about the grille (black lines), and explain
> what you want to do with the original (no grille) image?
----------------------------------------------------------------------------------------------

The code below processes the original image that I gave you and convert it in an image with grid..to obtain it, you have to run the code that tells you to choose an image and you just have to write '3an.bmp'

After that I want to extract the gray level values of the centers of the rectangular region formed by the grid (the black lines are saved in the variables LigneH and LigneV)
Then I put the results in another matrix that has the size (regions in vertical direction x regions in horizontal direction: for my image in this case size=4x8 but it can be another size: I have a lot of other images and the size change that's why I must run a code that processes any image)

Hope you understand what I mean to do
From: ImageAnalyst on
You need to replace that last part with something like this:

figure, imshow(ImageGrille);
title('Image avec grille');
axis on;
set(gcf, 'Position', get(0,'Screensize')); % Enlarge figure to full
screen.

%------------Grayscale values of center of each region-------
%INCOMPLETE
%
% for x = 1:LigneH:lign
% for y = 1:LigneV:col
% CaseGrille = ImageGris(x:LigneH,y:LigneV);
% end
% end
% Add the first and last columns.
LigneH = [1 LigneH col]
% Add the first and last rows.
LigneV = [1 LigneV lign]
lastTileX = length(LigneH)
lastTileY = length(LigneV)
figure;
set(gcf, 'Position', get(0,'Screensize')); % Enlarge figure to full
screen.

counter = 0;
for tileX = 1 : lastTileX-1
column1 = LigneH(tileX)
column2 = LigneH(tileX+1)
if column1 > col || column2 > col
% Skip bad ones.
continue;
end
for tileY = 1 : lastTileY-1
row1 = LigneV(tileY)
row2 = LigneV(tileY+1)
if row1 > lign || row2 > lign
% Skip bad ones.
continue;
end
subImage = grayImage(row1:row2, column1:column2);
subplot(lastTileY, lastTileX, counter+2);
imshow(subImage, []);
meanGrayLevel = mean(subImage(:))
counter = counter + 1
caption = sprintf('Mean = %.1f', meanGrayLevel);
title(caption);
end
end



But it appears that your LignV is messed up because it goes past the
last row of your image.

From: Sami Oueslati on
> But it appears that your LignV is messed up because it goes past the
> last row of your image.
---------------------------------------------------------------------------------------------------
Hi, thanks it looks good.

But LigneV is not messed up, LigneV represent the vertical black lines and LigneH the horizontal ones..you wrote ligneV = [1 LigneV lign] when the correct statement it's ligneV = [1 LigneV col] and for ligneH = [1 LigneH col] and the correst statement it's LigneH = [1 LigneH lign].

Maybe you confused between rows (lign) and columns (col)... May I change another statements? because in the figure the regions don't seem to be the ones of my image! the size it's not the same, normally I must have 5x8 and there's only 5x6 and the first column still moved. I think you've taken the mean values of the regions and in fact I need the gray value of the center of the region..And finally how to collect the gray values in a matrix 5x8??

Thanks a lot really.