Prev: Windows 7 Home Premium vs. Windows 7 Professional (using MATLAB R2007a or R2007b)
Next: extract field in excel
From: AZZA Foster on 30 Apr 2010 08:34 "AZZA Foster" <Aaron.Foster17(a)ntlworld.com> wrote in message <hrehkc$fi3$1(a)fred.mathworks.com>... > "AZZA Foster" <Aaron.Foster17(a)ntlworld.com> wrote in message <hregol$j32$1(a)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
From: AZZA Foster on 30 Apr 2010 10:12 "AZZA Foster" <Aaron.Foster17(a)ntlworld.com> wrote in message <hreins$rn7$1(a)fred.mathworks.com>... > "AZZA Foster" <Aaron.Foster17(a)ntlworld.com> wrote in message <hrehkc$fi3$1(a)fred.mathworks.com>... > > "AZZA Foster" <Aaron.Foster17(a)ntlworld.com> wrote in message <hregol$j32$1(a)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.
From: ImageAnalyst on 30 Apr 2010 10:33 On Apr 30, 10:12 am, "AZZA Foster" <Aaron.Foste...(a)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);
From: AZZA Foster on 30 Apr 2010 11:43 ImageAnalyst <imageanalyst(a)mailinator.com> wrote in message <4f8a04bb-8f89-4926-ba1e-339f886a68ca(a)n15g2000yqf.googlegroups.com>... > On Apr 30, 10:12 am, "AZZA Foster" <Aaron.Foste...(a)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
From: AZZA Foster on 30 Apr 2010 11:49
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. |