Cropping greyscale image based on pixel

4 visualizaciones (últimos 30 días)
victor law
victor law el 23 de Feb. de 2017
Comentada: victor law el 23 de Feb. de 2017
Hi all,
I intend to crop images based on its pixel value or intensity. Here are my images below, labeled as image1, image2... image 7.
All these images are from the taken from the object but replaced with different optical density filters. I performed a simple imcrop() rectangle and subplotted to obtain the following.
For example if I take image3, I am mostly interested in the center and would like to crop out that weird eclipse area.
I would like to somehow be able to define a range to crop and keep the cropped area. For each image, I will need to define a new range, depending on the section I want to keep or discard. Can I do something like, if the pixelvalue < 50, then make it transparent?
Later on, I would like to paste these cropped areas on top of each other.
Thanks, Victor

Respuesta aceptada

Peter O
Peter O el 23 de Feb. de 2017
The quick-n-dirty way that comes to mind is to just use a bitmask: 0 to toss a pixel's value and 1 to keep it. It's a little memory intensive but it won't care about the shape of the ROI.
For a given filtered image,
%Returns a logical matrix equal in size to your image, doing a per-pixel comparison.
Mask1 = (Im1 > 50);
Then to combine, just add everyone together with the bitmasks, performing a bitwise mult to only keep the pixels you want. The other pixels will be zero. So not exactly transparent, but since you're working in grayscale I suspect you don't have (or need) an alpha channel.
ImAll = Im1.*Mask1 + Im2.*Mask2 + ...
Obviously you could use N-D arrays instead of discrete variables and matrices and a half dozen other tricks if you wanted, depending on your end application. Is that sufficient? Or too coarse a solution?
  3 comentarios
victor law
victor law el 23 de Feb. de 2017
The code seems pretty small, but all I have done is,
c06 = double(b06) %Original Image1
c15 = double(b15) %Original Image2
Mask1 = (c06 > 200)
CroppedImage1 = Mask1.*c06 %Separating image based on pixel value for Image1
Mask2 = (c15 > 100);
CroppedImage2 = Mask2.*c15 %%Separating image based on pixel value for Image2
The rest is just a subplot comparison between original and cropped image.
victor law
victor law el 23 de Feb. de 2017
Nevermind, the solution worked after playing around with it.
Thank you very much Peter!

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 23 de Feb. de 2017
I'm not sure of the exact algorithms they use in HDR reconstruction. A simplistic view would be to extract non-saturated pixels and divide them by the transmissivity, then average or scale any pixels that show up in multiple images, as I said the prior time you asked this.

Community Treasure Hunt

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

Start Hunting!

Translated by