現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
How to extract particular pixel values from an image?
13 ビュー (過去 30 日間)
古いコメントを表示
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 日
sir, here extract means retrieval of those pixels, i mean only "1". and its a grayscale image and i converted it into binary image. how can i do this, please guide me!
回答 (4 件)
Walter Roberson
2012 年 12 月 24 日
[PixelRows, PixelColumns] = find( YourImage(:,:,1) == RedValue & YourImage(:,:,2) == GreenValue & YourImage(:,:,3) == BlueVaue );
Nikhil
2012 年 12 月 24 日
sir i appreciate your answer but my image is binary image, sorry i completely forgot to mention it!! Now what to do??
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 日
sir, i have number of image and in each image there is only one object present, so i am writing a single code that work for all the image. and for all the image the object's position is not fixed!! so sir what to do??? please drag me out of this!!
Nikhil
2012 年 12 月 26 日
http://www.dabi.temple.edu/~shape/MPEG7/dataset.html sir here you can see the database which i'm using for my project work.
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 日
Kris Sir, which link i had mentioned above that is database link, i mean the same database using for my project. and for further work i need to delete/remove the background but i got stuck here only.
how can i do this??
Image Analyst
2012 年 12 月 24 日
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 日
Sir, i have MPEG7 data set and in it each image consists of only one object. after i convert the image into binary image i will get only the values either 0 or 1 but for each image the object values is not at the same position. i want to extract the only values of "1" not 0. so i can get only object. # Sir as i am using im2bw('image.jpg'), got the binary values and i am storing it into the one variable so as we can access the value and its location from its variable, i mean its position but for each and every image object's position is not fixed!! # So sir please get me out of this difficulty.
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 日
sir, extract means i just want to retrieve the values of 1, where it is present in the image. so i can do feature extraction part as i'm doing project on object recognition. http://www.dabi.temple.edu/~shape/MPEG7/dataset.html, sir this is the link where you can see the data set.
Walter Roberson
2012 年 12 月 26 日
If you need to know the positions of the 1, then
find(TheBinaryImage)
Nikhil
2012 年 12 月 26 日
sir i need to retrieve those values,i mean "1" from the image where exactly the object is present. sir how can i do this??
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 日
yes sir, i had examine the regionprops() documentation but upto my knowledge it will crop the image in rectangular shape and return. but sir i need only that part where it is filled with "1". In image it is object(apple, brick, etc..). sir, how can i do this??
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 日
Mr. Walter Roberson, sir i want to retrieve perfect shape in my project. here you gave an example in that(in my project) i want the shape where 1 is present. and in my database (as mentioned above link) apple, brick etc are there so without caring the rest i just need to exact shape of apple, brick etc(i mean where the 1 is present).
Nikhil
2012 年 12 月 27 日
Image Analyst, Sir you are right may be i din't explain you my question properly. i just need to retrieve the shape(i mean where the 1 is present). For example in my database there are apple, brick, camel etc are there. so i just want to extract the shape of apple(means where white(1's)).
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 日
sir i need the shape
---
-1-
111
, here i just need to only 1 not the 0. here i just wrote "-" because i don't want that 0. and here in comment what i need is showing in a single line because it is not appearing in the three rows.
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 日
sir i just need output as triangle not the anything else. how could i get this??
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.
Image Analyst
2012 年 12 月 28 日
Nikhil
2012 年 12 月 28 日
Walter Roberson, Yes Sir but that is the recognition part to match those with database, here in my project i just need to extract the feature and one of the feature is to extract the part where object is present in the image. as i posted the link above of my database i just need to extract the apple, brick, camel etc i mean only the shape(white) not the background part(black).
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.
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 日
sir i need triangle(figure) as output, and if we will read with imread function we will get all 1's. an in my database i need apple, brick, camel as output(figure). only white area. not the [1 1 1 1] or [0 0 0;0 1 0;1 1 1]
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 日
no sir i want only the part where object is present, if we will crop then we might get the 0's but i want only object part of the image.
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 日
no sir i want it as figure( in my project it should give output as apple, camel etc). i just want to subtract the background from my image so remaining part is only object so i want that as output.
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 日
sir i want triangle drawn with no background.
you have asked me: "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?"
sir the above question is next part of my project.
right now i want only triangle to be drawn with no background. or in my project only apple, camel, etc(object) to be drawn with no background.
Sir how can i do it. really i got stuck here.
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 日
yes sir, but i have to follow that way only.
sir sorry to say but the code you gave is not working. it is not removing the background.
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 日
sir will you please mention what the value should i write in the function you mentioned above? i mean in the below function..
imagesc(YourImageData, 'Alphadata', YourImageData)
colormap(gray)
Nikhil
2013 年 1 月 3 日
MPEG-7 dataset..
sir you can download it from below link. http://www.imageprocessingplace.com/downloads_V3/root_downloads/image_databases/MPEG7_CE-Shape-1_Part_B.zip
Anuradhi Umayangani
2016 年 9 月 14 日
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));
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
アジア太平洋地域
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)