- What do you mean by highest value? Presumably your image is a colour image, so each pixel has r, g and b values. Do you mean the pixel that has the highest sum, r+b+g, or the highest g, or some other measure?
- What do you want to do about the fact that the square will go outside the original image? That is, suppose the pixel with the highest value is at x=100, y=100. A square centred on this will have a corner at x=-330, y=-330. Do you want to fill the undefined pixels with zeros or something, or resample the image so that a 960x960 square fits in, or something else?
Resize image to a square centred on a certain pixel
13 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Harry Cantor
le 9 Mar 2015
Commenté : Image Analyst
le 9 Mar 2015
Hi,
I have a camera that captures images with a size of 960 by 1280 pixels. I wanted to resize this image so that it is squared on the pixel of highest value, and has dimensions of 960 by 960. Could anyone suggest any codes to achieve this? The image format I am using is .bmp if that helps.
Thanks
Harry
2 commentaires
David Young
le 9 Mar 2015
Modifié(e) : David Young
le 9 Mar 2015
It will help with making a good answer if you could clarify a couple of points.
By the way, it doesn't matter how your image is stored on disk. You just use imread to read it into an array in main memory and work on that.
Réponse acceptée
Image Analyst
le 9 Mar 2015
Find the location first. Remember that there may be more than one pixel with the max value, but I assume you can figure this part out. Then, assuming get the edges. Let's say you want 960 by 960 centered on (y,x) = (rowMax, colMax).
[rows, columns, numberOfColorChannels] = size(grayImage);
width = 960;
halfWidth = width /2;
row1 = rowMax - halfWidth;
row2 = row1 + width - 1;
col1 = colMax - halfWidth;
col2 = col1 + width - 1;
if row1 < 1
row1 = 1;
end
if row2 > rows
row2 = rows;
end
if col1 < 1
col1 = 1;
end
if col2 > columns
col2 = columns;
end
newImage = grayImage(row1:row2, col1:col2);
2 commentaires
Image Analyst
le 9 Mar 2015
Great. Not bad for untested, off the top of my head code. Thanks for Accepting the answer.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Convert Image Type dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!