필터 지우기
필터 지우기

I am doing a peanut colour sorting project?can anybody help me with the code.

조회 수: 1 (최근 30일)
I have a rough code, but now I need to scan each row of the image and find HSV .please can anybody help me with the code.

채택된 답변

Walter Roberson
Walter Roberson 2018년 10월 11일
for row_number = 1 : size(YourRGBImage, 1)
hsv_of_row = rgb2hsv( YourRGBImage(row_number, :, :));
%now what?
end

추가 답변 (4개)

Image Analyst
Image Analyst 2018년 10월 11일
You might also look into rgb2ind() to do a rough labeling of your different color regions. Once they're labeled you can then convert the image to HSV and then use regionprops to get the HSV of each region.
  댓글 수: 2
Aatheeswaran M
Aatheeswaran M 2018년 10월 12일
편집: Walter Roberson 2018년 10월 12일
sir,iam a software intern , this is the project iam working on.i have just started in matlab, this is my rough code which i took from matlab example.
******************************************************************
[rgbimage,storedcoloredmap]=imread('C:/image.jpg');%storedclrmap=empty then it is not indexeds
[rows,colums,noofclrband]=size(rgbimage);%noofclrband=1itsmonochrome
subplot(3,4,1);
hrgb=imshow(rgbimage);%original image
hrgbpi=impixelinfo(hrgb);%to get the pixel info
hsvimage=rgb2hsv(rgbimage);%hsv image
himage=hsvimage(:,:,1); %h,s,v values
simage=hsvimage(:,:,2);
vimage=hsvimage(:,:,3);
subplot(3,4,2); %display and pixelinfo
h1=imshow(himage);
hhuepi=impixelinfo(h1);
subplot(3,4,3);
h2=imshow(simage);
hsatpi=impixelinfo(h2);
subplot(3,4,4);
h3=imshow(vimage);
hvalpi=impixelinfo(h3);
%histogram display
subplot(3,4,5)
[huecounts,huebinvalues]=imhist(himage);
maxcounthue=max(huecounts);
area(huebinvalues, huecounts, 'FaceColor', 'r');
grid on;
xlabel('Hue Value');
ylabel('Pixel Count');
subplot(3,4,6);
[saturationCounts, saturationBinValues] = imhist(simage);
maxCountSaturation = max(saturationCounts);
area(saturationBinValues, saturationCounts, 'FaceColor', 'g');
grid on;
xlabel('Saturation Value');
ylabel('Pixel Count');
subplot(3,4,7);
[valueCounts, valueBinValues] = imhist(vimage);
maxCountValue = max(valueCounts);
area(valueBinValues, valueCounts, 'FaceColor', 'b');
grid on;
xlabel('Value Value');
ylabel('Pixel Count');
%plot all together
subplot(3, 4, 8);
plot(huebinvalues, huecounts, 'r', 'LineWidth', 4);
grid on;
xlabel('Values');
ylabel('Pixel Count');
hold on;
plot(saturationBinValues, saturationCounts, 'g', 'LineWidth', 3);
plot(valueBinValues, valueCounts, 'b', 'LineWidth', 1);
%determining the threshold
hueThresholdLow = 0;
hueThresholdHigh = graythresh(himage);
saturationThresholdLow = graythresh(simage);
saturationThresholdHigh = 1.0;
%valueThresholdLow = graythresh(vimage);
valueThresholdLow=.80;
valueThresholdHigh = 1.0;
%masking value
hueMask = (himage >= hueThresholdLow) & (himage <= hueThresholdHigh);
saturationMask = (simage >= saturationThresholdLow) & (simage <= saturationThresholdHigh);
valueMask = (vimage >= valueThresholdLow) & (vimage <= valueThresholdHigh);
subplot(3, 4, 9);
imshow(hueMask, []);
subplot(3, 4, 10);
imshow(saturationMask, []);
subplot(3, 4, 11);
imshow(valueMask, []);
%the object to b masked
coloredObjectsMask = uint8(hueMask & saturationMask & valueMask);
subplot(3, 4, 12);
imshow(coloredObjectsMask, []);
%smallones get rid of it
coloredObjectsMask = uint8(bwareaopen(coloredObjectsMask, 100));
figure;
subplot(3, 3,1 );
imshow(coloredObjectsMask, []);
%smoothens the border
structuringElement = strel('disk', 4);
coloredObjectsMask = imclose(coloredObjectsMask, structuringElement);
subplot(3, 3, 2);
imshow(coloredObjectsMask, []);
coloredObjectsMask = imfill(logical(coloredObjectsMask), 'holes');
subplot(3, 3, 3);
imshow(coloredObjectsMask, []);
%make it similar to rgband plot rgb
coloredObjectsMask = cast(coloredObjectsMask, 'like', rgbimage);
maskedImageR = coloredObjectsMask .* rgbimage(:,:,1);
maskedImageG = coloredObjectsMask .* rgbimage(:,:,2);
maskedImageB = coloredObjectsMask .* rgbimage(:,:,3);
subplot(3, 3, 4);
imshow(maskedImageR);
subplot(3, 3, 5);
imshow(maskedImageG);
subplot(3, 3, 6);
imshow(maskedImageB);
%all together
maskedRGBImage = cat(3, maskedImageR, maskedImageG, maskedImageB);
subplot(3, 3, 8);
imshow(maskedRGBImage);
subplot(3, 3, 7);
imshow(rgbimage);%orinal img
subplot(3,3,9);
imshow(hsvimage);%hsv image
*******************************************************
but how can i sort good one and bad one from all these values? is there some other steps or values which has to be obtained for sorting? can you help me with necessary code or steps to be done further.
Image Analyst
Image Analyst 2018년 10월 12일
편집: Image Analyst 2018년 10월 12일
You've accepted an answer so I assume the above comment does not apply anymore.
If you still don't have a solution then attach your image.

댓글을 달려면 로그인하십시오.


Image Analyst
Image Analyst 2018년 10월 12일
Alright, Aatheeswaran, since you won't post your image I had to make a guess at what one would look like to give you a full demo. Run the attached m-file
  댓글 수: 7
Image Analyst
Image Analyst 2018년 10월 26일
이동: DGM 2023년 2월 12일
You should really consult a professional to get an imaging system that will get you images that can be analyzed. No professional industrial system would make images like
when you could set up a system with much, MUCH better image capture characteristics. I mean if we came up with an algorithm to handle those two types of images, then you'd just come along with some third and fourth type of image where the algorithm doesn't work on. So there is no sense in trying to solve this type of scenario now, not until you can get good images. Best would be uniform lighting, with a Color Checker chart in the field of view, uniform focus, top down (not an oblique angle), high depth of field, telecentric lens, etc. I design imaging systems all the time - you really need to get professional help. It's SO much easier to create an algorithm to work with a great image than so spend months perfecting an algorithm to handle crummy, variable images - something that just wouldn't be necessary if you had great images to start with.
Aatheeswaran M
Aatheeswaran M 2018년 10월 29일
이동: DGM 2023년 2월 12일
thank you, sir, for the advice.i will look into it.

댓글을 달려면 로그인하십시오.


bhadra j
bhadra j 2019년 2월 8일
hi all,
I am mtech student and i want to develp a matlab code to sort bad nuts.can anybody help me with the code in sorting this white peanut from the good one. i saw the above programes but could not sort them. iam new to matlab so can anybody guide me how to sort them .
i have attached two images with two background.

DGM
DGM 2023년 2월 12일
I have this demo I made for finding bad peanuts. I hope someone finds it helpful.
% read the peanut image
inpict = imread('peanuts.png');
% use color-based thresholding to isolate peanuts from background
labpict = rgb2lab(inpict);
th = [54.57 100; 22.82 53; 22.10 74.46];
th = permute(th,[3 2 1]);
mask = all((labpict >= th(1,1,:)) & (labpict <= th(1,2,:)),3);
% remove extraneous blobs from mask
mask = imfill(mask,'holes');
mask = bwareaopen(mask,2000);
% get object properties
S = regionprops(mask,'centroid');
% plot results
imshow(inpict); hold on
title('Location of Bad Peanuts')
for k = 1:numel(S)
hp = plot(S(k).Centroid(1),S(k).Centroid(2),'bx');
hp.MarkerSize = 20;
hp.LineWidth = 3;
end

카테고리

Help CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by