Borrar filtros
Borrar filtros

How to extract portions of image as matrix (not simple array) and how to draw a rectangle of the portion that was extracted?

2 visualizaciones (últimos 30 días)
Hi,
I need to extract portions of an image. Before doing it, I tranform the image to grey, and then I extract everything that is not black (pixel 0).
So, from this big portion (pixels that are not zero), I want to extract other 2 or 4 other portions of the same size. My problem is:
1) When I extract everything that is not black, I get an array, not a matrix (1 column, several lines), which makes the visualization of image different. How do I extract 4 parts (same size) from this array and show them as normal images (I mean: as matrix with lines and columns)? Is it possible or should I work with that array and get those portions as array too?
2) I want to draw in the image a rectangle that shows each portion of the image that will be extracted. I've been using rectangle function, without success. Do you suggest a better way to do it?
I've added my piece of code (I removed rectangle part, as it does not work well for me) and also a very simple image I've been using to better understand what I'm extracting.
If this is not easy to understand, please let me know.
Thank you in advance
clear;
clc;
I = imread('c:\testQueila3.png');
G = rgb2gray(I);
D = find(G~=0);
rect = G(D);
% imshow(rect);
imshow(rect,'InitialMagnification','fit');

Respuesta aceptada

Walter Roberson
Walter Roberson el 11 de Mayo de 2016
You need to be finding bounding boxes and using those to extract. Even if you choose to use a mask within the box, you still need to use a box.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by