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 で Axis Labels についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!