Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Image Processing of a Black and White Image

Subject: Image Processing of a Black and White Image

From: AZZA Foster

Date: 24 Apr, 2010 21:04:05

Message: 1 of 57

I have a Black and White image in which i would like to create a boundary box around a specific part.

In order to do this i need to somehow identify this region which has a large L shape around the data. ( The image is a 2D data matrix barcode) I wish to identify this L shape and draw a boundary box around the whole image.

I thinking of using the filt2 which is an ROI filter but im not sure how to implement it???
I appreciate any comments made

Subject: Image Processing of a Black and White Image

From: ImageAnalyst

Date: 25 Apr, 2010 03:07:06

Message: 2 of 57

Where's your image?
Post it to http://drop.io or somewhere, and then we can offer
suggestions. It's hard for me to visualize a bar code with some L-
shaped region around it, and what you consider the "whole image" to
be. I.e. wouldn't a box around the "whole image" just be a box on the
top row, bottom row, left column and right column? Or did you mean a
box around the bar code, or around the L-shaped region? I'm also
unclear as to why you're thinking of using a filter to find the region
- a photo would help me understand that.

Subject: Image Processing of a Black and White Image

From: AZZA Foster

Date: 25 Apr, 2010 10:15:08

Message: 3 of 57

Here is my image http://drop.io/ifihag5 , i have used the follwing to convert to black and white and extract the corners:
%%%%%%%%%%%%%%%%%%%%%%%
 
 image(Image3);figure(gcf);
Image4 = Image3 >= 100;
scaled2 = Image4 * 1.0;
level = graythresh (scaled2);
bw = im2bw (scaled2, level);
bw = bwareaopen (bw, 6);
horizontalProfile = max(bw, [], 1);
x1 = find(horizontalProfile, 1, 'first');
x2 = find(horizontalProfile, 1, 'last');
verticalProfile =max(bw, [], 2);
y1 = find(verticalProfile, 1, 'first');
y2 = find(verticalProfile, 1, 'last');
boxX = [x1 x2 x2 x1 x1];
boxY = [y1 y1 y2 y2 y1];
imshow(bw, []);
hold on;
plot (boxX,boxY,'r-');
cornerim_adjusted = imadjust (cornerim);
corner_peaks = imregionalmax (cornerim_adjusted);
corner_idx = find(corner_peaks == true);
[r g b] = deal (cornerim);
r(corner_idx) = 255;
g(corner_idx) = 255;
b(corner_idx) = 0;
RGB = cat(3,r,g,b);
figure,imshow (RGB);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

I Now need to tell Matlab to select an area with say 200 to 300 yellow blobs within a certain area of pixels and draw a box round it. This should pick out only the barcode. I can then overlay that box on the original image.

Subject: Image Processing of a Black and White Image

From: AZZA Foster

Date: 25 Apr, 2010 11:23:05

Message: 4 of 57

I think i have to define the yellow pixel areas as a blob definition.
so target area of 200x200 pixels, look for 80 - 150 blobs of pixel colour r = 1, g = 1 and b = 0;
Then are all the blobs in a 200x200 pixel area.

Im looking at something along these lines, just trying to figure out functions and code values.

Subject: Image Processing of a Black and White Image

From: AZZA Foster

Date: 25 Apr, 2010 13:45:22

Message: 5 of 57

Sorry the above code is incorrect, try this one LOL.

%%%%%%%%%%%%%%%%%%%%%%%%%%

 image(Image3);figure(gcf);
Image4 = Image3 >= 100;
scaled2 = Image4 * 1.0;
level = graythresh (scaled2);
bw = im2bw (scaled2, level);
bw = bwareaopen (bw, 6);
horizontalProfile = max(bw, [], 1);
x1 = find(horizontalProfile, 1, 'first');
x2 = find(horizontalProfile, 1, 'last');
verticalProfile =max(bw, [], 2);
y1 = find(verticalProfile, 1, 'first');
y2 = find(verticalProfile, 1, 'last');
boxX = [x1 x2 x2 x1 x1];
boxY = [y1 y1 y2 y2 y1];
imshow(bw, []);
hold on;
plot (boxX,boxY,'r-');
cornerim = cornermetric (bw);
cornerim_adjusted = imadjust (cornerim);
corner_peaks = imregionalmax (cornerim_adjusted);
corner_idx = find(corner_peaks == true);
[r g b] = deal (cornerim);
r(corner_idx) = 255;
g(corner_idx) = 255;
b(corner_idx) = 0;
RGB = cat(3,r,g,b);
figure,imshow (RGB);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Subject: Image Processing of a Black and White Image

From: AZZA Foster

Date: 25 Apr, 2010 17:43:07

Message: 6 of 57

Does anyone know if it is possible to create charcteristic parameters for bwboundaries??

e.g.

bwboundaries (image,charcteristic);
charcteristic = [0111000000000,
                      0111000000000,
                      0111000000000,
                      0111111111100,
                      0111111111100,
                      0000000000000;];
  Something that basically identifies an L shape??

Subject: Image Processing of a Black and White Image

From: ImageAnalyst

Date: 25 Apr, 2010 18:46:54

Message: 7 of 57

Not that I'm aware of. That is not an allowable argument for
bwboundaries(). You'd have to try something else like imfilter,
nlfilter, conv2, or something like that to basically make up a "hit or
miss filter". Or you can try a Harris corner detector if you're
looking to find corners.

Subject: Image Processing of a Black and White Image

From: ImageAnalyst

Date: 25 Apr, 2010 19:16:40

Message: 8 of 57

This looks like a machine vision application. Therefore you can crop
the image to known coordinates since your 2D bar code should be in
pretty much the same position in every image. If this is not the case
then you need to shelve your image processing until you get control of
your image acquisition situation (which looks pretty bad at the
moment). It's always better to start with a good image rather than a
bad one.

Subject: Image Processing of a Black and White Image

From: AZZA Foster

Date: 25 Apr, 2010 21:52:03

Message: 9 of 57

Thanks for the reply Image analyst

Yes this will be part of an image acquisition system. The image was pulled from the internet.
The image is about the resolution you would get from a CCD camera. The barcode would be clearer in actual use as the camera will be mounted above the image more or less central and will also be closer.

I have already made a few changes to the code above but i want to try and get my program working with this image as if it can pic up this barcode it should be able to pick up others with ease especially in the situation above.

 image(Image3);figure(gcf);
axis square;
Image4 = Image3 >= 100;
scaled2 = Image4 * 1.0;
level = graythresh (scaled2);
bw = im2bw (scaled2, level);
bw = bwareaopen (bw, 6);
bw = ~bw;
horizontalProfile = max(~bw, [], 1);
x1 = find(horizontalProfile, 1, 'first');
x2 = find(horizontalProfile, 1, 'last');
verticalProfile =max(~bw, [], 2);
y1 = find(verticalProfile, 1, 'first');
y2 = find(verticalProfile, 1, 'last');
boxX = [x1 x2 x2 x1 x1];
boxY = [y1 y1 y2 y2 y1];
imshow(bw, []);
hold on;
plot (boxX,boxY,'r-');
cornerim = cornermetric (bw);
cornerim_adjusted = imadjust (cornerim);
corner_peaks = imregionalmax (cornerim_adjusted);
corner_idx = find(corner_peaks == true);
[r g b] = deal (cornerim);
r(corner_idx) = 255;
g(corner_idx) = 255;
b(corner_idx) = 0;
RGB = cat(3,r,g,b);
figure, imshow (RGB);

I might abandon the corner detection method and have inverted the original image and will try a density and border detection approach.

Subject: Image Processing of a Black and White Image

From: ImageAnalyst

Date: 26 Apr, 2010 00:07:30

Message: 10 of 57

Maybe you could use a variance filter (go here
http://www.mathworks.com/matlabcentral/newsreader/view_thread/279711#737209
for a demo I posted on that this year). Then use morphological
closing to clump them (the dots) together, and then threshold and find
big blobs. Do a hole fill, then bwlabel and regionprops and finally
filter looking for a certain shape factor (perimeter squared over
area) that is representative of squares.

Or else try to find the pattern using a tophat (imtophat()) or bottom
hat filter.

Or you could try a hit or miss filter (bwhitmiss()) to try to find the
black dots surrounded by white areas. But this works on a binary
image so you need to have an image that can be thresholded nicely
before you can do this, a limitation the variance filter doesn't have.

Subject: Image Processing of a Black and White Image

From: AZZA Foster

Date: 26 Apr, 2010 14:08:09

Message: 11 of 57

Image Analyst, thank you for your input it is greatly appreciated. I have tried a few ideas with no great results. I will try all the methods suggested below and will let you know what the result has been.

Once again THANK YOU for your time, i will post back in a few days time to let you know of my progress.

AZZA

Subject: Image Processing of a Black and White Image

From: ImageAnalyst

Date: 26 Apr, 2010 22:28:10

Message: 12 of 57

On Apr 26, 10:08 am, "AZZA Foster" <Aaron.Foste...@ntlworld.com>
wrote:
> Image Analyst, thank you for your input it is greatly appreciated. I have tried a few ideas with no great results. I will try all the methods suggested below  and will let you know what the result has been.
>
> Once again THANK YOU for your time, i will post back in a few days time to let you know of my progress.
>
> AZZA
------------------------------------------------------------------------------------
Well you're welcome and good luck. I didn't produce any code because
you said this was just a sample image snagged from the internet, and
several times in the past I've put in time to solve an image like that
and then people said "but it doesn't work with all images." Well of
course they didn't supply all images and so the algorithm could be
only written to solve the one image they did supply (and hence I
wasted my time). As you can imagine it's much harder to write a
robust algorithm to solve a wide variety of images with vastly
different appearances than it is for just one single image. But good
luck, and you can post your images and/or code later if you need more
help.

Subject: Image Processing of a Black and White Image

From: AZZA Foster

Date: 26 Apr, 2010 23:08:03

Message: 13 of 57

This alogorithem will be designed just for Data Matrix codes only, not QR and other matrix types. I agree Analyst it may well be good for the program to recognise my original image, this is why the blob size matter as the data matrix will always have the L bend (" Finder Pattern ") and the tracking marks around the other two sides. The filters will need to leave these intact.

Subject: Image Processing of a Black and White Image

From: AZZA Foster

Date: 27 Apr, 2010 14:09:04

Message: 14 of 57

How are area descriptors written i keep getting the follwoing error.

L1 = bwlabel (closebw); % Convert closebw to a label matrix %
L2 = regionprops (closebw,'area','boundingbox');
W = [100.4 , 100.4];
NR = Length (W);

??? Undefined function or method 'Length' for input arguments of type 'double'.

Subject: Image Processing of a Black and White Image

From: Steven Lord

Date: 27 Apr, 2010 14:15:26

Message: 15 of 57


"AZZA Foster" <Aaron.Foster17@ntlworld.com> wrote in message
news:hr6r60$mc9$1@fred.mathworks.com...
> How are area descriptors written i keep getting the follwoing error.
>
> L1 = bwlabel (closebw); % Convert closebw to a label matrix %
> L2 = regionprops (closebw,'area','boundingbox');
> W = [100.4 , 100.4];
> NR = Length (W);
>
> ??? Undefined function or method 'Length' for input arguments of type
> 'double'.

Do you mean you want to compute the length (in this case 2) of the vector W?
In that case, use the lower-case length:

NR = length(W);

If you mean something else you will need to clarify what specifically you
mean to do.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ

Subject: Image Processing of a Black and White Image

From: AZZA Foster

Date: 27 Apr, 2010 14:32:04

Message: 16 of 57

Solved the previos issue, was just me being stupid.
L1 = bwlabel (closebw); % Convert closebw to a label matrix %
L2 = regionprops (closebw,'area','boundingbox');
W = [closebw.area];
NR = Length (W);

??? Attempt to reference field of non-structure array.

Should "Length" have some value assigned to it or is that the structure that NR is using ???

Subject: Image Processing of a Black and White Image

From: AZZA Foster

Date: 27 Apr, 2010 14:36:04

Message: 17 of 57

Thanks for pointing that out steve.

but im still getting this error, something to do with the length structure i think.

L1 = bwlabel (closebw); % Convert closebw to a label matrix %
L2 = regionprops (closebw,'area','boundingbox');
W = [closebw.area];
NR = length (W);

V = cat(1,D.BoundingBox);
figure,imshow (V);

Subject: Image Processing of a Black and White Image

From: AZZA Foster

Date: 27 Apr, 2010 14:45:22

Message: 18 of 57

LOL, sorted it out now guys. Cheers Steve, I think these 18hr days non stop are starting to have an affect.

Subject: Image Processing of a Black and White Image

From: AZZA Foster

Date: 27 Apr, 2010 21:58:04

Message: 19 of 57

Image Analyst and Lord Steve, THANKS for your help with the imaging process, after a bit more filtering and a few other additions i have finally got the boundary around the barcode on the sample image. I have tried it with a few other images and it seems to get so far about 75% through and destry the barcode, so i will have to place a few parameters in my code, to try and prevent that from happening in certain image situations.

Apart from that i am now labeling up the code and beginning to look at automating file inputs from a specific directory where all the images from the camera will be stored.

Keep you guys informed of my progress, cheers

AZZA

Subject: Image Processing of a Black and White Image

From: AZZA Foster

Date: 27 Apr, 2010 23:28:06

Message: 20 of 57

Does anyone know how to extra the image inside a bounding box??
I wish to extract the barcode from the bounding box.

Subject: Image Processing of a Black and White Image

From: AZZA Foster

Date: 27 Apr, 2010 23:32:18

Message: 21 of 57

No worries guys im going to play with the subimage function, just stubbled across it on another thread, posted by image analyst.

Subject: Image Processing of a Black and White Image

From: AZZA Foster

Date: 28 Apr, 2010 19:23:04

Message: 22 of 57

does anyone know how to open files incrementally e.g.
%%%Open image1

N = 1;
filename = (Image, (N));
Imread(filename, jpg); %% read-in image1.jpg
N = N++;

Subject: Image Processing of a Black and White Image

From: ImageAnalyst

Date: 28 Apr, 2010 20:07:57

Message: 23 of 57

On Apr 28, 3:23 pm, "AZZA Foster" <Aaron.Foste...@ntlworld.com> wrote:
> does anyone know how to open files incrementally e.g.
> %%%Open image1
>
> N = 1;
> filename = (Image, (N));
> Imread(filename, jpg);   %% read-in image1.jpg
> N = N++;

----------------------------------------------------------------
See section 4.12 of the FAQ:
http://matlabwiki.mathworks.com/MATLAB_FAQ#How_can_I_process_a_sequence_of_files.3F
Basically you use sprintf() to build up your filename.

Subject: Image Processing of a Black and White Image

From: AZZA Foster

Date: 28 Apr, 2010 23:35:20

Message: 24 of 57

Great help image analyst thanks alot, i'll sort the code out for that tomorrow/today.

Subject: Image Processing of a Black and White Image

From: AZZA Foster

Date: 29 Apr, 2010 13:21:05

Message: 25 of 57

http://drop.io/ifihag5

Image Analyst i have uploaded a figure file of my barcode that has been extracted from the original image. The problem i have is that the barcode is slanted, i know the method i need to use the barcode centered, but dont know how to implement it.

Center the barcode without using the rotation tool, i should be able to tell matlab, find the middle point of the whole barcode image, once this has been found position only the black pixels around this center point.

Any ideas helpful.

e.g. i was thinking of something like this:

%% Use the X and Y axis sizes of the Bounding Box image.

horizontalProfile = max(subimage, [], 1);
x3 = find(horizontalProfile, 1, 'first');
x4 = find(horizontalProfile, 1, 'last');
verticalProfile = max(subimage, [], 2);
y3 = find(verticalProfile, 1, 'first');
y4 = find(verticalProfile, 1, 'last');
boxX = [x1 x2 x2 x1 x1];
boxY = [y1 y1 y2 y2 y1];

%% Use x2 and y2 values to calculate thecentre of the bounding box.

Center = x2/2 , y2/2
%% This is where i got stuck, i need the intersection of "Center" given the two values obtained half way across the x axis and halfway up the y axis.

Then i can say "Somehow" Plot all the black pixels areound the center point specified.

Subject: Image Processing of a Black and White Image

From: AZZA Foster

Date: 29 Apr, 2010 13:38:04

Message: 26 of 57

Thinking aboutit i little more i dont think that method will work.
Basically i need to rotate the black region of the iamge so that it is square to the perimeter of the bounding box. ( But i cant use a manual rotate function, as this function has to be used on other images that may need varying degrees of rotation in order to square up the image ).

Subject: Image Processing of a Black and White Image

From: ImageAnalyst

Date: 29 Apr, 2010 14:23:01

Message: 27 of 57

AZZA Foster:
You might try using hough() or houghlines() to try to find the average
angle of the lines in the image. Sorry, I have no hough code that
works with your image, but there is example code in the help. Once
you find the angle, simply use imrotate to rotate it.

Subject: Image Processing of a Black and White Image

From: AZZA Foster

Date: 29 Apr, 2010 14:29:08

Message: 28 of 57

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <e48a314a-8f7e-4205-9f66-d0ccfc11b4d0@r6g2000vbh.googlegroups.com>...
> AZZA Foster:
> You might try using hough() or houghlines() to try to find the average
> angle of the lines in the image. Sorry, I have no hough code that
> works with your image, but there is example code in the help. Once
> you find the angle, simply use imrotate to rotate it.

Thanks Image Analyst, i was about to go down the increment of the rotating function route, but i will try this first.

Subject: Image Processing of a Black and White Image

From: AZZA Foster

Date: 29 Apr, 2010 15:52:04

Message: 29 of 57

Tried it Image Analyst and it didn't work, it would of done it i had changed all the filter settings, but i need code which is a bit more robust.

So after a bit of lunch and a hard think, i have come back with a method that will work automatically for ANY black&white image.

What i know, the bounding box tells me the X and Y dimension of the full image. So when an object in an image is rotated to fit an image better, what always happens, the X and Y axis always shrink, as an object that is not centered to an image area will always take up a larger area than one that has been centered.

COMMENT: x1 and y1 is the original size subimage bounding box.
SO HERE'S MY PLAN:
%% Rotate subimage by 1 degree clockwise %%
Loop CW
rotatedsubimage = imrotate (subimage,1)
%% Rotate subimage by 1 degree clockwise %%
Loop CCW
rotatedsubimage = imrotate (subimage,-1)
%% Place a bounding box around rotatedsubimage%%
 horizontalProfile = max(rotatedsubimage, [], 1);
x2 = find(horizontalProfile, 1, 'first');
x3 = find(horizontalProfile, 1, 'last');
verticalProfile =max(rotatedsubimage, [], 2);
y3 = find(verticalProfile, 1, 'first');
y4 = find(verticalProfile, 1, 'last');
boxX2 = [x1 x2 x2 x1 x1];
boxY2= [y1 y1 y2 y2 y1];

%% Compare, is the rotated bounding box larger or smaller than subimage(original)
%% if the y2 axis is smaller than y1 axis and x2 is smaller than x1 carry on rotating%%
if
y2 <= y1 , x2<=x1
goto Loop CW %% goto Loop Clockwise
 
%% if y2 is greater than y1 and x2 is greater than x1, then the image area is getting bigger,go counterclockwise instead %%
if
y2 > y1 , x2 > x1
goto Loop CCW

%% If rotatedsubimage bounding box(y2,x2) is equal to subimage boundingbox (x1,y1) %%
if
y2 == y1, x2 == x1 subimage
end
%%carry on with rest of code %%

Image Analyst will this layout work??
I need someone to sort out the loops for me, as i dont know how to make a continous loop using matlab, is it the same as C++ and assembly language software, which tend to use " for (;;)?? I dont know
I know that when the image is rotated the x and y axis DO change size, as i thought matlab may clip the image automatically, but thankfully not.

Subject: Image Processing of a Black and White Image

From: AZZA Foster

Date: 29 Apr, 2010 16:41:19

Message: 30 of 57

Sorry above code is incorrect in terms of its method, "subimage" needs to be updated,the code below has this included.
The x and y values are now also correct.

K=1 %% (INITIAL CONDITION)This is set so that only a clockwise or anticlockwise function is performed in the first 2 cycles of the program loop %%

%% Rotate subimage by 1 degree clockwise %%
if K = 1
Loop CW
rotatedsubimage = imrotate (subimage,1)

%% After rotation performed update subimage bounding box%%
horizontalProfile = max(subimage, [], 1);
x1 = find(horizontalProfile, 1, 'first');
x2 = find(horizontalProfile, 1, 'last');
verticalProfile =max(subimage, [], 2);
y1 = find(verticalProfile, 1, 'first');
y2 = find(verticalProfile, 1, 'last');
boxX = [x1 x2 x2 x1 x1];
boxY = [y1 y1 y2 y2 y1];
 

%% Rotate subimage by 1 degree counterclockwise %%
if K = 0
Loop CCW
rotatedsubimage = imrotate (subimage,-1)

%% After rotation performed update subimage bounding box%%
horizontalProfile = max(subimage, [], 1);
x1 = find(horizontalProfile, 1, 'first');
x2 = find(horizontalProfile, 1, 'last');
verticalProfile =max(subimage, [], 2);
y1 = find(verticalProfile, 1, 'first');
y2 = find(verticalProfile, 1, 'last');
boxX2 = [x1 x2 x2 x1 x1];
boxY2= [y1 y1 y2 y2 y1];

%% update subimage bounding box before performing size calculations, THEN loop %%
horizontalProfile = max(rotatedsubimage, [], 1);
x3 = find(horizontalProfile, 1, 'first');
x4 = find(horizontalProfile, 1, 'last');
verticalProfile =max(rotatedsubimage, [], 2);
y3 = find(verticalProfile, 1, 'first');
y4 = find(verticalProfile, 1, 'last');
boxX2 = [x3 x4 x4 x3 x3];
boxY2= [y3 y3 y4 y4 y3];


%% Compare, is the rotated bounding box larger or smaller than subimage(original)
%% if the y2 axis is smaller than y1 axis and x2 is smaller than x1 carry on rotating%%
if
y4 <= y2 , x4 <= x2
goto Loop CW %% goto Loop Clockwise
 
%% if y2 is greater than y1 and x2 is greater than x1, then the image area is getting bigger,go counterclockwise instead %%
if
y4 > y2 , x4 > x2
K -1 %% K Now equals 0 keep going counterclockwise%
goto Loop CCW

%% If rotatedsubimage bounding box(y4,x4) is equal to subimage boundingbox (x2,y2) %%
if
y4 == y2, x4 == x2 subimage %% when both bounding boxs are the same size,the image is central%%
end
%%carry on with rest of code %%

Subject: Image Processing of a Black and White Image

From: AZZA Foster

Date: 29 Apr, 2010 16:54:05

Message: 31 of 57

Here is my code with more corrections, i just need help with the loop's and the operators, thanks in advance AZZA

K = 1; %% (INITIAL CONDITION)This is set so that only a clockwise or anticlockwise function is performed in the first 2 cycles of the program loop %%

%% Rotate subimage by 1 degree clockwise %%
if
    K = 1;
Loop CW
rotatedsubimage = imrotate (subimage,1)

%% After rotation performed update subimage bounding box%%
horizontalProfile = max(subimage, [], 1);
x1 = find(horizontalProfile, 1, 'first');
x2 = find(horizontalProfile, 1, 'last');
verticalProfile =max(subimage, [], 2);
y1 = find(verticalProfile, 1, 'first');
y2 = find(verticalProfile, 1, 'last');
boxX = [x1 x2 x2 x1 x1];
boxY = [y1 y1 y2 y2 y1];
end

%% Rotate subimage by 1 degree counterclockwise %%
Loop CCW
rotatedsubimage = imrotate (subimage,-1)

%% After rotation performed update subimage bounding box%%
horizontalProfile = max(subimage, [], 1);
x1 = find(horizontalProfile, 1, 'first');
x2 = find(horizontalProfile, 1, 'last');
verticalProfile =max(subimage, [], 2);
y1 = find(verticalProfile, 1, 'first');
y2 = find(verticalProfile, 1, 'last');
boxX = [x1 x2 x2 x1 x1];
boxY = [y1 y1 y2 y2 y1];
end
%% update subimage bounding box before performing size calculations, THEN loop %%
horizontalProfile = max(rotatedsubimage, [], 1);
x3 = find(horizontalProfile, 1, 'first');
x4 = find(horizontalProfile, 1, 'last');
verticalProfile =max(rotatedsubimage, [], 2);
y3 = find(verticalProfile, 1, 'first');
y4 = find(verticalProfile, 1, 'last');
boxX2 = [x3 x4 x4 x3 x3];
boxY2= [y3 y3 y4 y4 y3];


%% Compare, is the rotated bounding box larger or smaller than subimage(original)
%% if the y2 axis is smaller than y1 axis and x2 is smaller than x1 carry on rotating%%
if
y4 <= y2 , x4 <= x2;
goto "Loop CW" %% goto Loop Clockwise
end
%% if y2 is greater than y1 and x2 is greater than x1, then the image area is getting bigger,go counterclockwise instead %%
if
y4 > y2 , x4 > x2;
goto "Loop CCW"

end
%% If rotatedsubimage bounding box(y4,x4) is equal to subimage boundingbox (x2,y2) %%
if
y4 == y2, x4 == x2; %% when both bounding boxs are the same size,the image is central%%
end
%%carry on with rest of code %%

Subject: Image Processing of a Black and White Image

From: ImageAnalyst

Date: 29 Apr, 2010 17:12:48

Message: 32 of 57

I don't have time to help you with this today. Maybe tomorrow if
we're lucky, but maybe not. And I could only do it if you uploaded
your cropped 2D bar code picture as a regular image (PNG, BMP, etc.)
rather than a MATLAB fig file.

Subject: Image Processing of a Black and White Image

From: AZZA Foster

Date: 29 Apr, 2010 17:24:05

Message: 33 of 57

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <7ee4eaa1-5489-4dc8-b762-4490234a8319@v37g2000vbv.googlegroups.com>...
> I don't have time to help you with this today. Maybe tomorrow if
> we're lucky, but maybe not. And I could only do it if you uploaded
> your cropped 2D bar code picture as a regular image (PNG, BMP, etc.)
> rather than a MATLAB fig file.

No worries ill upload all the files tonight if im still stuck, thanks AZZA

Subject: Image Processing of a Black and White Image

From: AZZA Foster

Date: 30 Apr, 2010 12:00:21

Message: 34 of 57

I have found out why my code is running in a continous loop, i am using the imrotate function, this function places a BLACK canvas on an area where it does not know what pixel to assign to that space, so anyone know how to tell image rotate to apply a WHITE canvas to rotated images???

Subject: Image Processing of a Black and White Image

From: AZZA Foster

Date: 30 Apr, 2010 12:15:08

Message: 35 of 57

"AZZA Foster" <Aaron.Foster17@ntlworld.com> wrote in message <hregol$j32$1@fred.mathworks.com>...
> I have found out why my code is running in a continous loop, i am using the imrotate function, this function places a BLACK canvas on an area where it does not know what pixel to assign to that space, so anyone know how to tell image rotate to apply a WHITE canvas to rotated images???

Just had another thought, is it possible to use an image mask to lay the original NON rotated image over the rotated image and extract all Black pixels that do not match the masked image?? (This should remove the canvas pixels)

Subject: Image Processing of a Black and White Image

From: AZZA Foster

Date: 30 Apr, 2010 12:34:04

Message: 36 of 57

"AZZA Foster" <Aaron.Foster17@ntlworld.com> wrote in message <hrehkc$fi3$1@fred.mathworks.com>...
> "AZZA Foster" <Aaron.Foster17@ntlworld.com> wrote in message <hregol$j32$1@fred.mathworks.com>...
> > I have found out why my code is running in a continous loop, i am using the imrotate function, this function places a BLACK canvas on an area where it does not know what pixel to assign to that space, so anyone know how to tell image rotate to apply a WHITE canvas to rotated images???
>
> Just had another thought, is it possible to use an image mask to lay the original NON rotated image over the rotated image and extract all Black pixels that do not match the masked image?? (This should remove the canvas pixels)

I have upladed both of my images ing JPG format, the first image is the one that HAS been rotated with the stupid black border marks round it.

The second is my extracted barcode image before rotation.

http://drop.io/ifihag5

AZZA

Subject: Image Processing of a Black and White Image

From: AZZA Foster

Date: 30 Apr, 2010 14:12:04

Message: 37 of 57

"AZZA Foster" <Aaron.Foster17@ntlworld.com> wrote in message <hreins$rn7$1@fred.mathworks.com>...
> "AZZA Foster" <Aaron.Foster17@ntlworld.com> wrote in message <hrehkc$fi3$1@fred.mathworks.com>...
> > "AZZA Foster" <Aaron.Foster17@ntlworld.com> wrote in message <hregol$j32$1@fred.mathworks.com>...
> > > I have found out why my code is running in a continous loop, i am using the imrotate function, this function places a BLACK canvas on an area where it does not know what pixel to assign to that space, so anyone know how to tell image rotate to apply a WHITE canvas to rotated images???
> >
> > Just had another thought, is it possible to use an image mask to lay the original NON rotated image over the rotated image and extract all Black pixels that do not match the masked image?? (This should remove the canvas pixels)
>
> I have upladed both of my images ing JPG format, the first image is the one that HAS been rotated with the stupid black border marks round it.
>
> The second is my extracted barcode image before rotation.
>
> http://drop.io/ifihag5
>
> AZZA

Right after long deliberation there are only 2 ways i can think of removing the black pixels that IMROTATE creates:

1) Somehow tell imrotate to fill in the background canvas pixels white, instead of black when it inserts the canvas.
Or
2) Use an image difference tool,
 but from what i have read, image difference functions look at pixel changes in X and Y coordinates and do not take into account that the full image is still in view it has just been rotated round by 1 degree. So all the X and Y co-ordinates are different on the rotated image compared to the refrence image.

Subject: Image Processing of a Black and White Image

From: ImageAnalyst

Date: 30 Apr, 2010 14:33:38

Message: 38 of 57

On Apr 30, 10:12 am, "AZZA Foster" <Aaron.Foste...@ntlworld.com>
wrote:
> Right after long deliberation there are only 2 ways i can think of removing the black pixels that IMROTATE creates:
>
> 1) Somehow tell imrotate to fill in the background canvas pixels white, instead of black when it inserts the canvas.
> Or
> 2) Use an image difference tool,
>  but from what i have read, image difference functions look at pixel changes in X and Y coordinates and do not take into account that the full image is still in view it has just been rotated round by 1 degree. So all the X and Y co-ordinates are different on the rotated image compared to the refrence image.
-------------------------------------------------------------------------------------------------------
Why do you want them to be white? Just for appearance sake?

Here's a quick and dirty method. It should work perfectly as long as
none of the pixels in the original image that touch the border have
the value 0. If they do, then the edges may be somewhat ragged (as
illustrated in this demo which uses the standard MATLAB demo image
tire.tif):

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.

% Change the current folder to the folder of this m-file.
% (The line of code below is from Brett Shoelson of The Mathworks.)
if(~isdeployed)
cd(fileparts(which(mfilename)));
end
subplotRows = 2;
subplotColumns = 3;
fontSize = 18;

% Read in standard MATLAB grayscale demo image.
grayImage = imread('tire.tif');
subplot(subplotRows, subplotColumns, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize);
set(gcf, 'Position', get(0,'Screensize')); % Enlarge figure to full
screen.

rotatedImage = imrotate(grayImage, 20);
subplot(subplotRows, subplotColumns, 2);
imshow(rotatedImage, []);
title('Rotated Image', 'FontSize', fontSize);

blackPixels = rotatedImage == 0;
subplot(subplotRows, subplotColumns, 3);
imshow(blackPixels, []);
title('Black Pixels', 'FontSize', fontSize);

noBordertriangles = imclearborder(blackPixels, 4);
subplot(subplotRows, subplotColumns, 4);
imshow(noBordertriangles, []);
title('No Triangles', 'FontSize', fontSize);

bordertriangles = logical(blackPixels - noBordertriangles);
subplot(subplotRows, subplotColumns, 5);
imshow(bordertriangles, []);
title('Border Triangles', 'FontSize', fontSize);

finalImage = rotatedImage;
finalImage(bordertriangles) = 255;
subplot(subplotRows, subplotColumns, 6);
imshow(finalImage, []);
title('White Border Triangles on Rotated Image', 'FontSize',
fontSize);

Subject: Image Processing of a Black and White Image

From: AZZA Foster

Date: 30 Apr, 2010 15:43:05

Message: 39 of 57

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <4f8a04bb-8f89-4926-ba1e-339f886a68ca@n15g2000yqf.googlegroups.com>...
> On Apr 30, 10:12 am, "AZZA Foster" <Aaron.Foste...@ntlworld.com>
> wrote:
> > Right after long deliberation there are only 2 ways i can think of removing the black pixels that IMROTATE creates:
> >
> > 1) Somehow tell imrotate to fill in the background canvas pixels white, instead of black when it inserts the canvas.
> > Or
> > 2) Use an image difference tool,
> >  but from what i have read, image difference functions look at pixel changes in X and Y coordinates and do not take into account that the full image is still in view it has just been rotated round by 1 degree. So all the X and Y co-ordinates are different on the rotated image compared to the refrence image.
> -------------------------------------------------------------------------------------------------------
> Why do you want them to be white? Just for appearance sake?
>
> Here's a quick and dirty method. It should work perfectly as long as
> none of the pixels in the original image that touch the border have
> the value 0. If they do, then the edges may be somewhat ragged (as
> illustrated in this demo which uses the standard MATLAB demo image
> tire.tif):
>
> 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.
>
> % Change the current folder to the folder of this m-file.
> % (The line of code below is from Brett Shoelson of The Mathworks.)
> if(~isdeployed)
> cd(fileparts(which(mfilename)));
> end
> subplotRows = 2;
> subplotColumns = 3;
> fontSize = 18;
>
> % Read in standard MATLAB grayscale demo image.
> grayImage = imread('tire.tif');
> subplot(subplotRows, subplotColumns, 1);
> imshow(grayImage, []);
> title('Original Grayscale Image', 'FontSize', fontSize);
> set(gcf, 'Position', get(0,'Screensize')); % Enlarge figure to full
> screen.
>
> rotatedImage = imrotate(grayImage, 20);
> subplot(subplotRows, subplotColumns, 2);
> imshow(rotatedImage, []);
> title('Rotated Image', 'FontSize', fontSize);
>
> blackPixels = rotatedImage == 0;
> subplot(subplotRows, subplotColumns, 3);
> imshow(blackPixels, []);
> title('Black Pixels', 'FontSize', fontSize);
>
> noBordertriangles = imclearborder(blackPixels, 4);
> subplot(subplotRows, subplotColumns, 4);
> imshow(noBordertriangles, []);
> title('No Triangles', 'FontSize', fontSize);
>
> bordertriangles = logical(blackPixels - noBordertriangles);
> subplot(subplotRows, subplotColumns, 5);
> imshow(bordertriangles, []);
> title('Border Triangles', 'FontSize', fontSize);
>
> finalImage = rotatedImage;
> finalImage(bordertriangles) = 255;
> subplot(subplotRows, subplotColumns, 6);
> imshow(finalImage, []);
> title('White Border Triangles on Rotated Image', 'FontSize',
> fontSize);
>
>

Image Analyst the bounding box will only shrink to the edge of the outermost black pixel in the image, i need the bounding box to shrink around only the rotated black pixels ONLY. This due to imrotate creating black pixrls in areas where no colour has been defined.
If you use my images and run the following you will see my problem:
"Subimage" being the barcode image WITHOUT the silly lines around the edge.

rotatedsubimage = imrotate (subimage,2,'loose');
imshow (rotatedsubimage);
%% Apply the crop method helps but because the image is moved 1 degree the crop function still shows the pixels that imrotate placed in because it didnt know what to do with undefined pixels so it just coloured them black.

rotatedsubimage = imrotate (subimage,1,'crop');
imshow (rotatedsubimage);

AZZA

Subject: Image Processing of a Black and White Image

From: AZZA Foster

Date: 30 Apr, 2010 15:49:04

Message: 40 of 57


Just a long shot, is it possible to rotate the bounding box by 1 degree with the image?? As this will also solve my problem.

Subject: Image Processing of a Black and White Image

From: AZZA Foster

Date: 30 Apr, 2010 16:05:22

Message: 41 of 57

"AZZA Foster" <Aaron.Foster17@ntlworld.com> wrote in message <hreu5g$gf3$1@fred.mathworks.com>...
>
> Just a long shot, is it possible to rotate the bounding box by 1 degree with the image?? As this will also solve my problem.

Just ran your code Analyst, not bad, but i need at least 1 outer blob on on each edge on the barcode, so when i run the bounding box code it binds around the outer edges of the blobs, AKA the barcode itself only.

Im going to have a sit done for a bit and have a serious think, it has work before. Its all about the finding the right function (s) for the job, it just takes me ages to string something together. LOL

Subject: Image Processing of a Black and White Image

From: AZZA Foster

Date: 30 Apr, 2010 16:21:04

Message: 42 of 57

I have found the following link, where a similar problem has been raised.
http://www.mathworks.com/matlabcentral/newsreader/view_thread/259513#676274

Ashish says use tformarray(), image analyst have you had much experience in using this, do you think it would work in my situation??

The matlab link below describes it as a spatial transformation, which would help,
but no image examples are shown.
http://www.mathworks.com/access/helpdesk/help/toolbox/images/tformarray.html

Subject: Image Processing of a Black and White Image

From: AZZA Foster

Date: 30 Apr, 2010 17:01:20

Message: 43 of 57

"AZZA Foster" <Aaron.Foster17@ntlworld.com> wrote in message <hrf01g$jfd$1@fred.mathworks.com>...
> I have found the following link, where a similar problem has been raised.
> http://www.mathworks.com/matlabcentral/newsreader/view_thread/259513#676274
>
> Ashish says use tformarray(), image analyst have you had much experience in using this, do you think it would work in my situation??
>
> The matlab link below describes it as a spatial transformation, which would help,
> but no image examples are shown.
> http://www.mathworks.com/access/helpdesk/help/toolbox/images/tformarray.html

IMAGE ANALYST, I think i have cracked IT!!!!!

>> filtered5 = impyramid(subimage,'reduce');
>> figure ,imshow (filtered5);

impyramid function seems to of removed the pixels that imrotate placed inside the edges of the image. Can someone please explain BASICALLY how impyramid works?????
As the matlab explanation is confusing.

AZZA

Subject: Image Processing of a Black and White Image

From: AZZA Foster

Date: 30 Apr, 2010 17:12:07

Message: 44 of 57

"AZZA Foster" <Aaron.Foster17@ntlworld.com> wrote in message <hrf2d0$ohm$1@fred.mathworks.com>...
> "AZZA Foster" <Aaron.Foster17@ntlworld.com> wrote in message <hrf01g$jfd$1@fred.mathworks.com>...
> > I have found the following link, where a similar problem has been raised.
> > http://www.mathworks.com/matlabcentral/newsreader/view_thread/259513#676274
> >
> > Ashish says use tformarray(), image analyst have you had much experience in using this, do you think it would work in my situation??
> >
> > The matlab link below describes it as a spatial transformation, which would help,
> > but no image examples are shown.
> > http://www.mathworks.com/access/helpdesk/help/toolbox/images/tformarray.html
>
> IMAGE ANALYST, I think i have cracked IT!!!!!
>
> >> filtered5 = impyramid(subimage,'reduce');
> >> figure ,imshow (filtered5);
>
> impyramid function seems to of removed the pixels that imrotate placed inside the edges of the image. Can someone please explain BASICALLY how impyramid works?????
> As the matlab explanation is confusing.
>
> AZZA

I forgot to look at the image size, it has halfed, so i thought i would do:


>> filtered7 = impyramid (filtered5,'expand');
>> figure, imshow (filtered7);

to see if the border pixels had come back and they didn't, YAY, so if anyone using imrotate needs to get rid of there pixels that imrotate creates then this is one of the easier methods, BUT it does affect the image as well, IM ONLY AFTER A BOUNDING BOX AOUND THE WHOLE IMAGE, so im alright doing it this way.

Subject: Image Processing of a Black and White Image

From: AZZA Foster

Date: 30 Apr, 2010 17:29:06

Message: 45 of 57

"AZZA Foster" <Aaron.Foster17@ntlworld.com> wrote in message <hrf317$6ke$1@fred.mathworks.com>...
> "AZZA Foster" <Aaron.Foster17@ntlworld.com> wrote in message <hrf2d0$ohm$1@fred.mathworks.com>...
> > "AZZA Foster" <Aaron.Foster17@ntlworld.com> wrote in message <hrf01g$jfd$1@fred.mathworks.com>...
> > > I have found the following link, where a similar problem has been raised.
> > > http://www.mathworks.com/matlabcentral/newsreader/view_thread/259513#676274
> > >
> > > Ashish says use tformarray(), image analyst have you had much experience in using this, do you think it would work in my situation??
> > >
> > > The matlab link below describes it as a spatial transformation, which would help,
> > > but no image examples are shown.
> > > http://www.mathworks.com/access/helpdesk/help/toolbox/images/tformarray.html
> >
> > IMAGE ANALYST, I think i have cracked IT!!!!!
> >
> > >> filtered5 = impyramid(subimage,'reduce');
> > >> figure ,imshow (filtered5);
> >
> > impyramid function seems to of removed the pixels that imrotate placed inside the edges of the image. Can someone please explain BASICALLY how impyramid works?????
> > As the matlab explanation is confusing.
> >
> > AZZA
>
> I forgot to look at the image size, it has halfed, so i thought i would do:
>
>
> >> filtered7 = impyramid (filtered5,'expand');
> >> figure, imshow (filtered7);
>
> to see if the border pixels had come back and they didn't, YAY, so if anyone using imrotate needs to get rid of there pixels that imrotate creates then this is one of the easier methods, BUT it does affect the image as well, IM ONLY AFTER A BOUNDING BOX AOUND THE WHOLE IMAGE, so im alright doing it this way.


Just to see, i tried expanding first then reducing and myimage size stayed the same AND there was like ONE pixel missing from the image when zoomed in, so to get rid of imrotate canvas without affecting your image as well i did the following:

filtered5 = impyramid(subimage,'expand');
figure, imshow (filtered5);
filtered7 = impyramid (filtered5,'reduce');
figure, imshow (filtered7);

HAPPY DAYS!!!

AZZA

Subject: Image Processing of a Black and White Image

From: AZZA Foster

Date: 30 Apr, 2010 17:36:04

Message: 46 of 57

"AZZA Foster" <Aaron.Foster17@ntlworld.com> wrote in message <hrf317$6ke$1@fred.mathworks.com>...
> "AZZA Foster" <Aaron.Foster17@ntlworld.com> wrote in message <hrf2d0$ohm$1@fred.mathworks.com>...
> > "AZZA Foster" <Aaron.Foster17@ntlworld.com> wrote in message <hrf01g$jfd$1@fred.mathworks.com>...
> > > I have found the following link, where a similar problem has been raised.
> > > http://www.mathworks.com/matlabcentral/newsreader/view_thread/259513#676274
> > >
> > > Ashish says use tformarray(), image analyst have you had much experience in using this, do you think it would work in my situation??
> > >
> > > The matlab link below describes it as a spatial transformation, which would help,
> > > but no image examples are shown.
> > > http://www.mathworks.com/access/helpdesk/help/toolbox/images/tformarray.html
> >
> > IMAGE ANALYST, I think i have cracked IT!!!!!
> >
> > >> filtered5 = impyramid(subimage,'reduce');
> > >> figure ,imshow (filtered5);
> >
> > impyramid function seems to of removed the pixels that imrotate placed inside the edges of the image. Can someone please explain BASICALLY how impyramid works?????
> > As the matlab explanation is confusing.
> >
> > AZZA
>
> I forgot to look at the image size, it has halfed, so i thought i would do:
>
>
> >> filtered7 = impyramid (filtered5,'expand');
> >> figure, imshow (filtered7);
>
> to see if the border pixels had come back and they didn't, YAY, so if anyone using imrotate needs to get rid of there pixels that imrotate creates then this is one of the easier methods, BUT it does affect the image as well, IM ONLY AFTER A BOUNDING BOX AOUND THE WHOLE IMAGE, so im alright doing it this way.

IM LIEING, damn it, doing the above jsut stretches the image. IT will get rid of the lines created by imrotate, but at the expense of stretching your image to fill the space.

Subject: Image Processing of a Black and White Image

From: ImageAnalyst

Date: 30 Apr, 2010 18:07:49

Message: 47 of 57

Well then just put your cursor in imrotate and hit control-D to get to
the source code. Then search for padarray and replace the argument 0
with 255 so that it will pad with 255 (white). Then (very important)
save the file as new file called imrotate_whitefill.m so you don't
overwrite the original imrotate.

Pretty simple fix.

Subject: Image Processing of a Black and White Image

From: AZZA Foster

Date: 30 Apr, 2010 18:50:24

Message: 48 of 57

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <fdf599ea-5a5e-4b9a-985b-9f5ede8636b8@v18g2000vbc.googlegroups.com>...
> Well then just put your cursor in imrotate and hit control-D to get to
> the source code. Then search for padarray and replace the argument 0
> with 255 so that it will pad with 255 (white). Then (very important)
> save the file as new file called imrotate_whitefill.m so you don't
> overwrite the original imrotate.
>
> Pretty simple fix.

Absolute Legend!!!!!!!!, i didn't know how to get to source code, i didn't think it was that easy.
I knew it was possible but i didnt know if imrotate would be that easy to change, thanks Image Analyst. I am used to using Visual Studio and Autodesk, so im still not familar with all the works.

LEGEND!!!!!!!!!!!!!!!!!!!!!

Subject: Image Processing of a Black and White Image

From: ImageAnalyst

Date: 30 Apr, 2010 19:12:28

Message: 49 of 57

On Apr 30, 12:21 pm, "AZZA Foster" <Aaron.Foste...@ntlworld.com>
wrote:
> I have found the following link, where a similar problem has been raised.http://www.mathworks.com/matlabcentral/newsreader/view_thread/259513#...
>
> Ashish says use tformarray(), image analyst have you had much experience in using this, do you think it would work in my situation??
>
> The matlab link below describes it as a spatial transformation, which would help,
> but no image examples are shown.http://www.mathworks.com/access/helpdesk/help/toolbox/images/tformarr...

------------------------------------------------------------------------------
Yes, I've done it that way. I have one file where I ran the corners
of the image through tformfwd and found out where they went to, and
then used poly2mask but I didn't feel like digging it up and posting
it. However it's short - only a few lines. But I think in your case,
it might be best and easiest just to make your own version of imrotate
that pads the array with white, just like you wanted, and just like I
explained how to do in my prior post.
-ImageAnalyst

Subject: Image Processing of a Black and White Image

From: AZZA Foster

Date: 30 Apr, 2010 19:25:21

Message: 50 of 57

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <fdf599ea-5a5e-4b9a-985b-9f5ede8636b8@v18g2000vbc.googlegroups.com>...
> Well then just put your cursor in imrotate and hit control-D to get to
> the source code. Then search for padarray and replace the argument 0
> with 255 so that it will pad with 255 (white). Then (very important)
> save the file as new file called imrotate_whitefill.m so you don't
> overwrite the original imrotate.
>
> Pretty simple fix.

Just made the change and saved the file, work like a charm!!, Scratching my head and trying different functions for about 8 hours and all it need was me to input 3 numbers into an m.file. Im so happy, BUT SO ANGRY at the same time. LOL
THANKS IMAGE ANALYST !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Subject: Image Processing of a Black and White Image

From: AZZA Foster

Date: 1 May, 2010 15:17:20

Message: 51 of 57

"AZZA Foster" <Aaron.Foster17@ntlworld.com> wrote in message <hrfar1$cln$1@fred.mathworks.com>...
> ImageAnalyst <imageanalyst@mailinator.com> wrote in message <fdf599ea-5a5e-4b9a-985b-9f5ede8636b8@v18g2000vbc.googlegroups.com>...
> > Well then just put your cursor in imrotate and hit control-D to get to
> > the source code. Then search for padarray and replace the argument 0
> > with 255 so that it will pad with 255 (white). Then (very important)
> > save the file as new file called imrotate_whitefill.m so you don't
> > overwrite the original imrotate.
> >
> > Pretty simple fix.
>
> Just made the change and saved the file, work like a charm!!, Scratching my head and trying different functions for about 8 hours and all it need was me to input 3 numbers into an m.file. Im so happy, BUT SO ANGRY at the same time. LOL
> THANKS IMAGE ANALYST !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Image analyst how do i get rid of the ZERO padding in imrotate, as the change above has change the black pixels to white, which is good, but it would be better if i could get rid of the ZERO padding in imroate also, can i just delete the whole padding line???

Subject: Image Processing of a Black and White Image

From: ImageAnalyst

Date: 1 May, 2010 15:28:22

Message: 52 of 57

On May 1, 11:17 am, "AZZA Foster" <Aaron.Foste...@ntlworld.com> wrote:
> Image analyst how do i get rid of the ZERO padding in imrotate, as the change above has change the black pixels to white, which is good, but it would be better if i could get rid of the ZERO padding in imroate also, can i just delete the whole padding line???
--------------------------------------------------------------------------------

Use the 'crop' option of imrotate to clip off the corners that get
rotated outside the original boundaries.

Subject: Image Processing of a Black and White Image

From: AZZA Foster

Date: 1 May, 2010 15:31:06

Message: 53 of 57

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <f5a7c5af-be56-4e36-86e8-5bcb18e2452f@37g2000yqm.googlegroups.com>...
> On May 1, 11:17 am, "AZZA Foster" <Aaron.Foste...@ntlworld.com> wrote:
> > Image analyst how do i get rid of the ZERO padding in imrotate, as the change above has change the black pixels to white, which is good, but it would be better if i could get rid of the ZERO padding in imroate also, can i just delete the whole padding line???
> --------------------------------------------------------------------------------
>
> Use the 'crop' option of imrotate to clip off the corners that get
> rotated outside the original boundaries.

I changed the [2,2] padding size to [0,0], which should mean no padding?? hopefully.

Subject: Image Processing of a Black and White Image

From: AZZA Foster

Date: 1 May, 2010 16:03:05

Message: 54 of 57

"AZZA Foster" <Aaron.Foster17@ntlworld.com> wrote in message <hrhhfq$oti$1@fred.mathworks.com>...
> ImageAnalyst <imageanalyst@mailinator.com> wrote in message <f5a7c5af-be56-4e36-86e8-5bcb18e2452f@37g2000yqm.googlegroups.com>...
> > On May 1, 11:17 am, "AZZA Foster" <Aaron.Foste...@ntlworld.com> wrote:
> > > Image analyst how do i get rid of the ZERO padding in imrotate, as the change above has change the black pixels to white, which is good, but it would be better if i could get rid of the ZERO padding in imroate also, can i just delete the whole padding line???
> > --------------------------------------------------------------------------------
> >
> > Use the 'crop' option of imrotate to clip off the corners that get
> > rotated outside the original boundaries.
>
> I changed the [2,2] padding size to [0,0], which should mean no padding?? hopefully.

The padding size still had no affect, i tell you what im trying to do, im trying to put a bounding box around around the rotatedbarcode.

Using this code the box is being placed around the padding cells, not the black area of the image.
Youll see what i mean if you put this code in using the barcode image supplied at
http://drop.io/ifihag5 (Dont use the barcode with the black padding cells on it).

subimage3 = imrotate_whitefill (subimage2, 8,'crop');
horizontalProfile2 = max(subimage3, [], 1);
    x5 = find(horizontalProfile2, 1, 'first');
    x6 = find(horizontalProfile2, 1, 'last');
    verticalProfile2 =max(subimage3, [], 2);
    y5 = find(verticalProfile2, 1, 'first');
    y6 = find(verticalProfile2, 1, 'last');
    boxX3 = [x5 x6 x6 x5 x5];
    boxY3 = [y5 y5 y6 y6 y5];
 imshow (subimage3, []);
hold on;
plot (boxX3,boxY3,'r-');

You see i need the box around the black region, so i can monitor the barcode rotation around the X and Y axis until the barcode is central.

Subject: Image Processing of a Black and White Image

From: AZZA Foster

Date: 1 May, 2010 16:07:05

Message: 55 of 57

Just to add "image analyst" i used the crop and loose parameter but the crop function will not crop over the padding cells.
I need a padding cell remover. Im going to have a browse around to see if one exists.

Subject: Image Processing of a Black and White Image

From: AZZA Foster

Date: 1 May, 2010 17:17:05

Message: 56 of 57

Dont worry i got round it, by inverting the picture after rotation and then placing the bounding box round the ROI.

Thanks for giving suggestion I A ;)

Subject: Image Processing of a Black and White Image

From: AZZA Foster

Date: 9 Oct, 2010 14:12:03

Message: 57 of 57

Great the new matlab release is out, due to the addition made in the image toolbox, i can carry on my work.

Great Job MATHWORKS!!!!!!!!!

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us