Need help regarding image processing
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
How to add/introduce text and scratches in a gray scale image in matlab? I need to generate random scratches at any postion within the image of my interest.Please Tell me in an easy and lucid way. Also provide some basic codes not advanced one, which is easily understandable.
채택된 답변
Image Analyst
2021년 8월 14일
If you have the Computer Vision Toolbox, you can use insertText() to burn text into the image.
To introduce scratches it depends if they're straight or curved and if they have variable thickness or not. If they're just simple straight lines of one pixel, then simply use rand() to get a point, then again to get a point a distance away from it. You can use rand() to get random numbers for both the angle and length of the scratch. Then use polyfit() to get the equation of the line and polyfit() to get all the coordinates in between those endpoints. Then just loop over those burning some value, such as zero into it.
Is this your homework? Otherwise if your attempts over a half hour don't work let me know and I'll help. It's going to be something like
% Demo by Image Analyst to generate straight line not anti-aliased lines
% (scratches) in a gray scale image.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
%--------------------------------------------------------------------------------------------------------
% READ IN IMAGE
grayImage = imread('cameraman.tif');
% Get the dimensions of the image.
% numberOfColorChannels should be = 1 for a gray scale image, and 3 for an RGB color image.
[rows, columns, numberOfColorChannels] = size(grayImage)
if numberOfColorChannels > 1
% It's not really gray scale like we expected - it's color.
% Extract the red channel (so the magenta lines will be white).
grayImage = grayImage(:, :, 1);
end
%--------------------------------------------------------------------------------------------------------
% Display the image.
subplot(1, 2, 1);
imshow(grayImage, []);
axis('on', 'image');
title('Original Image', 'FontSize', fontSize, 'Interpreter', 'None');
impixelinfo;
hFig = gcf;
hFig.WindowState = 'maximized'; % May not work in earlier versions of MATLAB.
drawnow;
numScratches = 200
for s = 1 : numScratches
xy1 = rand(1,2);
x1 = columns * xy1(1);
y1 = rows * xy1(2);
lineLength = 100 * rand(1);
angle = 360 * rand(1);
x2 = x1 + lineLength * cosd(angle);
y2 = y1 + lineLength * sind(angle);
coefficients = polyfit([x1,x2], [y1,y2], 1);
% Get lots of x so we don't have "gaps" in line.
allX = linspace(x1, x2, rows);
allY = round(polyval(coefficients, allX));
% Now round x
allX = round(allX);
for k = 1 : length(allY)
if allY(k) > rows || allX(k) > columns || allY(k) < 1 || allX(k) < 1
continue; % Skip pixels outside of image.
end
grayImage(allY(k), allX(k)) = 0;
end
subplot(1, 2, 2);
imshow(grayImage); % Display your original image.
drawnow;
end
caption = sprintf('With %d scratches in it', numScratches);
title(caption, 'FontSize', fontSize);

Adapt as needed and report back.
댓글 수: 7
Arghya Pathak
2021년 8월 14일
편집: Arghya Pathak
2021년 8월 14일
Thank you very much for answering. Actually I need to create curve ,straight both type of scratches of variable thickness. I want to introduce some scratches,missing pixel elements in the gray scale image. I will run this code and inform you tomorrow.
You might be more realistic if you segment out some actual scratches from real images, then you'll have a "library" of realistic scratches. Then use random numbers to vary the location, rotation, and size of them before pasting them onto the image. If I had this as a real project (as opposed to just some play or homework project), that's what I'd do.
Actually I am not that much accustomed with programming so I need a basic and easy method.
Alright, then I guess since you're not that experienced with programming you'll just have to use the basic easy method I gave you code for. Maybe someday you'll be able to do it the more realistic way I mentioned. Thanks for Accepting the answer.
Arghya Pathak
2021년 8월 15일
편집: Arghya Pathak
2021년 8월 15일
Thanks for you cooperation. Can you please suggest me how I can get expertise in writing the image processing programs in matlab for different applications like image inpainting,noise removal etc. Is there any good source to learn the programs from basic and get experienced ?? Actually I have not found a good source till now, I have searched a lot but get only elementary idea not in detail. I want to learn the step wise detail of those standard programming and the theory related with each of the steps. So that I can be able to modify them according to my need.Please help me.
My favorite book is the "Image Processing Handbook" by John Russ. A huge variety of examples from a wide variety of fields. Covers a lot of different operations. Very light on the math so it's easy to follow.
Another book is by Steve Eddins and uses MATLAB to go through examples.
I think both are still available on Amazon.com.
Another good book available online is
Arghya Pathak
2021년 8월 16일
편집: Arghya Pathak
2021년 8월 16일
Okay.Thank you very much for your support.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Image Preview and Device Configuration에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 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)
