How to extract particular pixel values from an image?
이전 댓글 표시
Hello,
I'm doing project on image processing, and in one of my module i need to extract the particular bunch of the pixels.I know the values of that pixel but i'm not getting how exactly to extract that values. so please help me to get out of this!
댓글 수: 2
Walter Roberson
2012년 12월 24일
What do you mean by "extract" in this case?
Are the pixels RGB or grayscale?
Nikhil
2012년 12월 26일
답변 (4개)
Walter Roberson
2012년 12월 24일
[PixelRows, PixelColumns] = find( YourImage(:,:,1) == RedValue & YourImage(:,:,2) == GreenValue & YourImage(:,:,3) == BlueVaue );
Nikhil
2012년 12월 24일
0 개 추천
댓글 수: 7
Walter Roberson
2012년 12월 24일
Then what do you mean when you say that you need to extract a bunch of pixels? If you know the locations then just
YourImage(Row, Column)
and if you have a list of row and column pairs then
YourImage(sub2idx(size(YourImage), rows, columns)
Nikhil
2012년 12월 26일
Nikhil
2012년 12월 26일
Image Analyst
2012년 12월 26일
Like I said, post your image.
Nikhil
2012년 12월 26일
Kris
2013년 1월 2일
Dear Nikhil, Are you sure those are the images or they are just for example??...if so, please share the original image you are working on through flickr.com or picasa, tiny pic or any other photo sharing site...
Also, I feel that the labeling of image will be helpful for you..try image labeling once you label the regions of your image, it will be relatively easy to extract them...try once this might be helpful...
Nikhil
2013년 1월 2일
Image Analyst
2012년 12월 24일
0 개 추천
You say
- You have a binary image (which means value of 0 and 1)
- You know the values in the particular bunch (either 0, 1, or both of course)
- You need to extract their values (which will again be either 0 or 1 or both)
So the question remains,
- Do you know the locations of the "particular bunch" of pixels?
- If you already know their values then what exactly does it mean that you need to extract their values? You mean you want a vector that is the length of the "particular bunch" and has the 0 or 1 values in the vector? Like your image is 1 megapixel but you want a vector of pixel values from a small 1000 pixel chunk in the image?
댓글 수: 41
Nikhil
2012년 12월 26일
Image Analyst
2012년 12월 26일
This doesn't answer my questions. You haven't really said what "extract" means to you. I can tell you now that the value of your binary object is 1 at every pixel, but I don't think that's what you want. The position of every "1" pixel is available from regionprops but that is not really a final answer and again, not what I think you really want or need. It's time for you to post your image so we can discuss it further. http://www.mathworks.com/matlabcentral/answers/7924-where-can-i-upload-images-and-files-for-use-on-matlab-answers
Nikhil
2012년 12월 26일
Walter Roberson
2012년 12월 26일
If you need to know the positions of the 1, then
find(TheBinaryImage)
Nikhil
2012년 12월 26일
Walter Roberson
2012년 12월 26일
The result of find() will tell you where each individual pixel of the object is. If you prefer you can use
[r, c] = find(TheBinaryImage);
and then pixel #K is at r(K), c(K)
Might I suggest you examine the documentation for regionprops() ?
Nikhil
2012년 12월 26일
Walter Roberson
2012년 12월 26일
regionprops() will not do any cropping. regionprops() is for returning information about the image.
Image Analyst
2012년 12월 26일
편집: Image Analyst
2012년 12월 26일
Nikhil, you are asking the wrong questions. You don't need to find out the values of where the image is 1 (white) or their values. LIke we've been telling you, the values will all be 1, and the image itself tells you where those "1" pixels are, or if you want them in (row, column) format ( which you definitely DON'T), then you can use the find() function. But you're asking the wrong questions - questions that will get you useless stuff you don't need, because you already have the information or know it.
What you should be asking is "How can I measure X, Y, Z, etc." and the answer to that is to use regionprops(). Walter and I can't stress this enough. For example, how can I measure area, solidity, Euler number, perimeter length, etc. And another useless question is "how can I crop it?" - that doesn't matter because you don't need to. There is no need to crop those images on your web page. It's just not necessary to make the measurements of area, etc. You can make those measurements perfectly well without cropping, without knowing that the pixel values (which we've discussed are all 1 anyway), and without knowing the rows and column of every white pixel. Please believe me. I do this all day long, every day for a living. Please review my demo: http://www.mathworks.com/matlabcentral/fileexchange/25157-image-segmentation-tutorial-blobsdemo. It should explain everything.
Walter Roberson
2012년 12월 26일
Suppose, Nikhil, that you had the 3 x 3 image
000
010
111
then what output would you be hoping to get for the "location" of the 1's in this image?
Nikhil
2012년 12월 27일
Nikhil
2012년 12월 27일
Walter Roberson
2012년 12월 27일
It would help us if you were to respond to my earlier question. Repeating it,
Suppose, Nikhil, that you had the 3 x 3 image
000
010
111
then what output would you be hoping to get for the "location" (or shape) of the 1's in this image?
Nikhil
2012년 12월 27일
편집: Walter Roberson
2012년 12월 27일
Walter Roberson
2012년 12월 27일
Show us what you would want the output to be. A specific output. For example are you looking for the output "triangle", or are you looking for the output [3, 5, 6, 9] which is the linear indices, or are you looking for the output [3 2 3 3] [1 2 3 3] which is row values and column values, or are you looking for a shape descriptor such as (-1,1),(1,0),(0,1) which represents the (r,c) offsets needed to trace a path through from the lower-left corner, or ... ?
Nikhil
2012년 12월 27일
Image Analyst
2012년 12월 27일
편집: Image Analyst
2012년 12월 27일
Wow, this is like pulling teeth. You can't have a matrix with nothing, like a dash that you showed. A matrix is a 2D array of numbers. SOMETHING has to be there, such as zeros, in which case the original matrix is what you want. If you don't want the zeros, then do you want this: [1 1 1 1] instead? That is a linear array, because, remember, you can't have a 2D numerical array with dashes instead of a number.
Walter Roberson
2012년 12월 27일
So what you are asking for is that the shape somehow be recognized and an identification of the shape be returned? If so then that is a very different task than "extracting pixel values from the image", and is a lot more work. You would need to do "feature extraction" and match those extracted features against the features of the known database items, finding the closest match in the database.
Nikhil
2012년 12월 28일
Nikhil
2012년 12월 28일
Walter Roberson
2012년 12월 28일
Go back to the 3 x 3 example I gave above. What is the exact values you would want to output for that example? It was
000
010
111
Show the exact output you would want from that.
Nikhil
2012년 12월 29일
Image Analyst
2012년 12월 29일
편집: Image Analyst
2012년 12월 29일
Aaaaaaand, we come full circle.
I think I'll bail out now, unless Nikhil can answer the question properly, like he wants [1 1 1 1] or [0 0 0;0 1 0; 1 1 1], and how either of those could possibly be useful in any way at all to him.
Walter Roberson
2012년 12월 29일
Do you mean you need the character string 'triangle' as the output ?
Nikhil
2012년 12월 30일
Walter Roberson
2012년 12월 30일
Are you asking how to crop the image to its bounding box ? I am referring back here to "one of the feature is to extract the part where object is present in the image". That probably does not mean "just the 1's", that probably means that to trim down to the bounding box. For example in the example
000
010
111
the top row is just background, so the "interesting" part of the figure is
010
111
and that is probably what is being asked for.
Nikhil
2012년 12월 31일
Walter Roberson
2012년 12월 31일
So you want the "1" and the "1 1 1" together, right? And what data representation do you want for that? An array like
[1]
[1 1 1]
with the [1] "over" the center "1" because it came from the center? Or do you want
[1]
[1 1 1]
with it not being relevant that the [1] came from the center?
Or do you want
[1 1 1 1]
Or do you want the coordinates of the 1's, such as [2 2] [3 1] [3 2] [3 3] ?
Nikhil
2012년 12월 31일
Walter Roberson
2012년 12월 31일
편집: Walter Roberson
2012년 12월 31일
You want the triangle drawn with no background? Or you want it to return
[- - -]
[- 1 -]
[1 1 1]
except with nothing at all where the "-" are?
Or you want it to return the string 'triangle' ?
Or you want it to return a reference to the triangle shape in the database, having looked in the database and figured out that the triangle shape there was the best match? Perhaps you are wanting to return the name of the file in the database that most closely matches the input of
[0 0 0]
[0 1 0]
[1 1 1]
??
Nikhil
2012년 12월 31일
Walter Roberson
2012년 12월 31일
Okay, we can draw it, but what then? Are you going to work on the drawing of the triangle somehow?
Here is the drawing:
imagesc(YourImageData, 'Alphadata', YourImageData)
colormap(gray)
Image Analyst
2012년 12월 31일
This is becoming very entertaining. You're a real trooper Walter. A persistent one too. By the way, you should probably start your own answer so you get the credit, since I've bailed out long ago and am merely chuckling on the sidelines now.
Walter Roberson
2013년 1월 1일
Feature extraction from a drawing of the shape is considerably more tedious than feature extraction from the binary matrix.
Nikhil
2013년 1월 2일
Walter Roberson
2013년 1월 2일
What you are seeing as background is the axes background. You can set the axes 'color' property to 'none'
set(gca, 'color', 'none')
Nikhil
2013년 1월 2일
Walter Roberson
2013년 1월 2일
What is the name of your black-and-white image array?
Nikhil
2013년 1월 3일
Anuradhi Umayangani
2016년 9월 14일
0 개 추천
Hi, I have a matrix with only 0's & 1 's .I actually it is a square devided in to 9 equal squares some are coloured in black and some quares are white.this master square is printed in a white background.it has a black outline.I want to crop the square from the white background.do u know a way to do that. i need to write the program to identify the margine by itself
댓글 수: 3
Image Analyst
2016년 9월 14일
Use imcrop(). Or else indexing. Post your image in a new question if you want more help, since Nikhil probably doesn't care about your problem like the rest of us do.
snehal jaipurkar
2016년 10월 24일
If I am having a color image and I want to find the total no of pixels in a specific range of pixel values then what should I do????and how to find out the range of pixel values in a certain region of an image???
Image Analyst
2016년 10월 24일
You can take the histogram of each channel:
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
[countsR, edgesR] = imhist(redChannel);
[countsG, edgesG] = imhist(greenChannel);
[countsB, edgesB] = imhist(blueChannel);
To do it with a masked image, put the binary image mask as an index to the images.
% Extract the individual red, green, and blue
% color channels but only in the masked region(s);
[countsR, edgesR] = imhist(redChannel(mask));
[countsG, edgesG] = imhist(greenChannel(mask));
[countsB, edgesB] = imhist(blueChannel(mask));
카테고리
도움말 센터 및 File Exchange에서 Image display and manipulation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!