Confuse About How to CROP IMAGE AND REMOVING OF LIGHT

1 visualizzazione (ultimi 30 giorni)
I Have thesis on my college,, and my lecturer reject my method about how to crop and removing of light on it,,
this link problem that my lecture told and must do : <http://tinypic.com/view.php?pic=2091t8j&s=6>
_____________________
% i wanna try with simply m-file 1st
i = imread ('picture1'); i =imread( 'picture2');
%how then ???
  4 Commenti
Ryan
Ryan il 6 Giu 2012
Others have already answered parts 1 and 3 for you in your previous questions. I don't think correcting the image perspective will be easy. Personally, I would use an image editing software such as Photoshop to correct the warping before processing. I believe the answer for correcting the distortion in MATLAB lies in the link that Walter Roberson shared.
Possibly something here could help: http://www.csse.uwa.edu.au/~pk/research/matlabfns/#projective
KURNIAWAN
KURNIAWAN il 6 Giu 2012
but , rotation picture still have black background colour?

Accedi per commentare.

Risposta accettata

Image Analyst
Image Analyst il 6 Giu 2012
I've used imtransform before. It's not that hard. It's been a while since I looked at this code, but here's a snippet of where I "straightened" an image:
originalImage = imread(filename);
% subplot(1, 2, 1);
imshow(originalImage);
% hold on;
title('Original Image', 'FontSize', 18);
set(gcf, 'units','normalized','outerposition',[0 0 1 1]); % Maximize figure.
[rows, columns, numberOfColors] = size(originalImage)
userPrompt = sprintf('Left click at the centers of the corner spots on the 96 well plate\ngoing counter-clockwise from the upper left spot.\nFor the 4th spot (upper right) right-click to finish the quadrilateral.');
uiwait(msgbox(userPrompt));
[binaryMask, xCorners, yCorners] = roipolyold();
numberOfVertices= length(xCorners);
if numberOfVertices ~= 5
userPrompt = sprintf('You clicked %d points.\nPlease click exactly 4 point only.', numberOfVertices-1);
uiwait(msgbox(userPrompt));
return;
end
fprintf(1, 'x=%.1f ', xCorners);
fprintf(1, '\n');
fprintf(1, 'y=%.1f ', yCorners);
% Draw the quadrilateral.
hold on;
plot([xCorners(1) xCorners(2) xCorners(3) xCorners(4) xCorners(1)], [yCorners(1) yCorners(2) yCorners(3) yCorners(4) yCorners(1)], 'linewidth', 3, 'color', [1 0 1]); % Top line
caption = sprintf('(%.1f, %.1f)', xCorners(1), yCorners(1));
text(xCorners(1)-25, yCorners(1)+9, caption, 'fontsize', 8, 'Color', [1 1 0]);
caption = sprintf('(%.1f, %.1f)', xCorners(2), yCorners(2));
text(xCorners(2)-25, yCorners(2)+9, caption, 'fontsize', 8, 'Color', [1 1 0]);
caption = sprintf('(%.1f, %.1f)', xCorners(3), yCorners(3));
text(xCorners(3)-25, yCorners(3)+9, caption, 'fontsize', 8, 'Color', [1 1 0]);
caption = sprintf('(%.1f, %.1f)', xCorners(4), yCorners(4));
text(xCorners(4)-25, yCorners(4)+9, caption, 'fontsize', 8, 'Color', [1 1 0]);
% Create the desired coordinates;
x1 = mean([xCorners(1) xCorners(2)])
x2 = mean([xCorners(3) xCorners(4)])
y1 = mean([yCorners(1) yCorners(4)])
y2 = mean([yCorners(2) yCorners(3)])
% T = maketform('projective',U,X) builds a TFORM struct T for a two-dimensional projective transformation
% that maps each row of U to the corresponding row of X.
% The U and X arguments are each 4-by-2 and define the corners of input and output quadrilaterals.
% No three corners can be collinear.
U = [xCorners(1), yCorners(1);...
xCorners(2), yCorners(2);...
xCorners(3), yCorners(3);...
xCorners(4), yCorners(4)]
X = [x1 y1; x1 y2; x2 y2; x2 y1]
T = maketform('projective', U, X);
% tformfwd([10 20],T)
% Let's see where the corners of the image get moved to.
imageCornersX = [1 1 columns columns];
imageCornersY = [1 rows rows 1];
[mappedCornerLocationsX mappedCornerLocationsY] = tformfwd(T, imageCornersX, imageCornersY);
fprintf(1, '%6.3f\n', mappedCornerLocationsX);
fprintf(1, '%6.3f\n', mappedCornerLocationsY);
newUpperLeftX = min(mappedCornerLocationsX)
newUpperLeftY = min(mappedCornerLocationsY)
% Assign markers at the corners so we can find them in the transformed image
% since they won't be at the desired locations anymore (if the image rotated at all).
% originalImage = single(originalImage);
% originalImage(int32(y1), int32(x1)) = 9999.;
% originalImage(int32(y1), int32(x2)) = 9999.;
% originalImage(int32(y2), int32(x1)) = 9999.;
% originalImage(int32(y2), int32(x2)) = 9999.;
% Transform (warp) the image.
% transformedImage = imtransform(originalImage, T, 'Size', [rows columns]);
transformedImage = imtransform(originalImage, T);
% subplot(1,2,2);
figure;
imshow(transformedImage, []);
set(gcf, 'units','normalized','outerposition',[0 0 1 1]); % Maximize figure.
title('Transformed image', 'FontSize', 18);
drawnow;
hold on;

Più risposte (1)

Walter Roberson
Walter Roberson il 6 Giu 2012
I have not used that myself so I do not know how difficult it will be for you to remove the bowing, but you should at the very least be able to do the rotation to align the bottom of the image with the y axis.
  3 Commenti
Walter Roberson
Walter Roberson il 6 Giu 2012
The link I gave is not a tutorial: it is a reference page. The imtransform() routine is not just for rotation. Look at the Horizontal Shear example: any routine that can create horizontal shear can be used to remove existing horizontal shear in an object (your tile have some horizontal shear.)
We could give you code that would crop the image, leaving the largest possible rectangle that has no background in it. Your lecturer would not be happy about that solution. The word "warp" that is in that first image you post is requiring you to do more than just crop out the inconvenient parts: it is requiring you to transform the image so that its edges are fairly rectangular, without throwing away any of the foreground parts of the picture. You need to hold on to (some of) that black background while you do the image transformations, until you finally get the interesting part of the image all squared up; once it is squared up, you can crop away the extra background, not before.

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by